Files
OpenBB/openbb_platform/core
Shreyansh 7b7f012aa9 fix(finra): use persistent session to prevent TooManyRedirects (#7443)
* fix(finra): use persistent session to prevent TooManyRedirects

Resolves #6972.

The FINRA OTC data fetching functions (get_finra_weeks, get_finra_data,
get_full_data) previously created new HTTP sessions for each request.
When making dozens of sequential API calls to aggregate weekly data,
this caused Cloudflare's bot protection on api.finra.org to trigger
redirect loops, resulting in a TooManyRedirects error.

Changes:
- Refactored get_finra_weeks and get_finra_data to accept an optional
  session parameter via kwargs.
- Updated get_full_data to create a single requests.Session and perform
  a pre-flight GET to finra.org to establish Cloudflare cookies before
  making API calls.
- The session is reused across all requests within a single data fetch
  operation, preventing the redirect loop.
- Removed hardcoded User-Agent from get_finra_data in favor of the
  platform's standard user agent set by get_requests_session.
- Increased timeout for weeklyDownloadDetails from 3s to 20s for
  consistency and reliability.

* Apply Black Formatting

* perf(finra): use async requests for concurrent weekly data fetching

Addresses reviewer feedback on PR #7443.

The get_full_data function previously made up to 52 sequential POST
requests to fetch weekly OTC data, resulting in poor performance.

This commit adds async equivalents (aget_finra_weeks, aget_finra_data,
aget_full_data) that use the platform's amake_request utility and
asyncio.gather to fetch all weeks concurrently through a shared
aiohttp session.

The FinraOTCAggregateFetcher now uses aextract_data, which is natively
supported by the platform's Fetcher base class.

The pre-flight GET to finra.org for Cloudflare cookie establishment
is preserved in the async path.

* fix(finra): return all rows from data fetching instead of just the first one

* run black, add symbol field to data model, and recapture test cassette

* mypy

---------

Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>
2026-04-07 19:50:43 +00:00
..
2025-12-05 03:10:57 +00:00

Open Data Platform by OpenBB

Open Data Platform by OpenBB (ODP) is the open-source toolset that helps data engineers integrate proprietary, licensed, and public data sources into downstream applications like AI copilots and research dashboards.

ODP operates as the "connect once, consume everywhere" infrastructure layer that consolidates and exposes data to multiple surfaces at once: Python environments for quants, OpenBB Workspace and Excel for analysts, MCP servers for AI agents, and REST APIs for other applications.

Overview

The Core extension is used as the basis for building and integrating Open Data Platform Python packages. It provides the necessary classes and structures for standardizing and handling data. It is also responsible for generating a REST API and Python package static assets, which operate independently and interface with various consumption vehicles.

Typically, this library will be used as a project dependency, and extended.

Go to the documentation for information on getting started.

Prerequisites

  • Python >=3.10,<3.14
  • Familiarity with FastAPI and Pydantic.

Installation

Installing through pip:

pip install openbb-core

Note that, the openbb-core is an infrastructural component of the OpenBB Platform. It is not intended to be used as a standalone package.

Build

Build the Python application, with installed extensions, by running:

openbb-build

Key Features

  • Standardized Data Model (Data Class): A flexible and dynamic Pydantic model capable of handling various data structures.
  • Standardized Query Params (QueryParams Class): A Pydantic model for handling querying to different providers.
  • Dynamic Field Support: Enables handling of undefined fields, providing versatility in data processing.
  • Robust Data Validation: Utilizes Pydantic's validation features to ensure data integrity.
  • API Routing Mechanism (Router Class): Simplifies the process of defining API routes and endpoints - out of the box Python and Web endpoints.

Bugs

Report bugs on Github by opening a new issue, or commenting on an already open one, with all the details.

License

This project is licensed under the AGPL-3.0 License - see the LICENSE.md file for details.