Prerequisite refactor: - Consolidate duplicate _to_dicts into shared obb_utils.to_list - Add fetch_historical and first_or_empty helpers to obb_utils Phase 1 - Local computation (no provider risk): - Group I: 12 technical indicators (ATR, ADX, Stoch, OBV, Ichimoku, Donchian, Aroon, CCI, Keltner, Fibonacci, A/D, Volatility Cones) - Group J: Sortino, Omega ratios + rolling stats (variance, stdev, mean, skew, kurtosis, quantile via generic endpoint) - Group H: ECB currency reference rates Phase 2 - FRED/Federal Reserve providers: - Group C: 10 fixed income endpoints (treasury rates, yield curve, auctions, TIPS, EFFR, SOFR, HQM, commercial paper, spot rates, spreads) - Group D: 11 economy endpoints (CPI, GDP, unemployment, PCE, money measures, CLI, HPI, FRED search, balance of payments, Fed holdings, FOMC documents) - Group E: 5 survey endpoints (Michigan, SLOOS, NFP, Empire State, BLS search) Phase 3 - SEC/stockgrid/FINRA providers: - Group B: 4 equity fundamental endpoints (management, dividends, SEC filings, company search) - Group A: 4 shorts/dark pool endpoints (short volume, FTD, short interest, OTC dark pool) - Group F: 3 index/ETF enhanced (S&P 500 multiples, index constituents, ETF N-PORT) Phase 4 - Regulators: - Group G: 5 regulatory endpoints (COT report, COT search, SEC litigation, institution search, CIK mapping) Security hardening: - Service-layer allowlists for all getattr dynamic dispatch - Regex validation on date, country, security_type, form_type params - Exception handling in fetch_historical - Callable guard on rolling stat dispatch Total: 32 existing + 67 new = 99 endpoints, all free providers.
86 lines
2.7 KiB
Python
86 lines
2.7 KiB
Python
import logging
|
|
|
|
import uvicorn
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
# Patch curl_cffi to use safari TLS fingerprint instead of chrome.
|
|
# curl_cffi's chrome impersonation triggers BoringSSL SSL_ERROR_SYSCALL on
|
|
# some networks; safari works reliably. This must happen before any import
|
|
# that creates a curl_cffi Session (yfinance, openbb).
|
|
import curl_cffi.requests as _cffi_requests
|
|
|
|
_orig_session_init = _cffi_requests.Session.__init__
|
|
|
|
def _patched_session_init(self, *args, **kwargs):
|
|
if kwargs.get("impersonate") == "chrome":
|
|
kwargs["impersonate"] = "safari"
|
|
_orig_session_init(self, *args, **kwargs)
|
|
|
|
_cffi_requests.Session.__init__ = _patched_session_init
|
|
|
|
from openbb import obb
|
|
from config import settings
|
|
|
|
# Register optional provider credentials with OpenBB
|
|
if settings.fred_api_key:
|
|
obb.user.credentials.fred_api_key = settings.fred_api_key
|
|
from routes import router
|
|
from routes_sentiment import router as sentiment_router
|
|
from routes_macro import router as macro_router
|
|
from routes_technical import router as technical_router
|
|
from routes_quantitative import router as quantitative_router
|
|
from routes_calendar import router as calendar_router
|
|
from routes_market import router as market_router
|
|
from routes_shorts import router as shorts_router
|
|
from routes_fixed_income import router as fixed_income_router
|
|
from routes_economy import router as economy_router
|
|
from routes_surveys import router as surveys_router
|
|
from routes_regulators import router as regulators_router
|
|
|
|
logging.basicConfig(
|
|
level=settings.log_level.upper(),
|
|
format="%(asctime)s %(levelname)s %(name)s: %(message)s",
|
|
)
|
|
|
|
app = FastAPI(
|
|
title="OpenBB Investment Analysis API",
|
|
version="0.1.0",
|
|
description="REST API for stock data and rule-based investment analysis, powered by OpenBB SDK.",
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_origins,
|
|
allow_credentials=False,
|
|
allow_methods=["GET", "POST"],
|
|
allow_headers=["Content-Type", "Authorization"],
|
|
)
|
|
|
|
app.include_router(router)
|
|
app.include_router(sentiment_router)
|
|
app.include_router(macro_router)
|
|
app.include_router(technical_router)
|
|
app.include_router(quantitative_router)
|
|
app.include_router(calendar_router)
|
|
app.include_router(market_router)
|
|
app.include_router(shorts_router)
|
|
app.include_router(fixed_income_router)
|
|
app.include_router(economy_router)
|
|
app.include_router(surveys_router)
|
|
app.include_router(regulators_router)
|
|
|
|
|
|
@app.get("/health", response_model=dict[str, str])
|
|
async def health() -> dict[str, str]:
|
|
return {"status": "ok"}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run(
|
|
"main:app",
|
|
host=settings.host,
|
|
port=settings.port,
|
|
reload=settings.debug,
|
|
)
|