Nasdaq Data Integration
Relevant source files
The following files were used as context for generating this wiki page:
The Nasdaq Data Integration module in the Stolgo library provides a specialized interface for fetching historical stock data directly from Nasdaq's API. It serves as a data provider within the Stolgo ecosystem, enabling users to retrieve price action data for US stocks which can then be used for technical analysis, such as identifying candlestick patterns or breakouts.
Sources: lib/stolgo/nasdaq.py:1-40, README.md:1-55
Architecture and Components
The integration is built around two primary classes: NasdaqUrls and Nasdaq. NasdaqUrls manages the construction of API endpoints and the necessary HTTP headers to emulate a browser request, while Nasdaq handles the business logic for data retrieval, pagination/adjustment, and error handling.
Class Relationship Diagram
The following diagram illustrates the relationship between the Nasdaq module and the underlying request handling system.
Data Retrieval Process
The data retrieval process involves calculating the required date range, constructing a specific URL, and executing an HTTP GET request. The system supports two modes of execution: standard requests and a Curl fallback for cloud environments.
Request Flow
The following sequence diagram demonstrates the flow of a data request through the system.
Data Adjustment Logic
If the initial request does not return the number of rows (periods) requested by the user, the __get_data_adjusted method is triggered. It calculates the missing time range and performs recursive calls to fetch additional data, which is then merged using pandas.append.
Sources: lib/stolgo/nasdaq.py:48-73
Technical Specifications
Configuration and Defaults
The module uses several default constants to ensure stability and provide sensible fallbacks when user parameters are missing.
| Constant | Default Value | Description |
|---|---|---|
DEFAULT_TIMEOUT | 5 seconds | Timeout for HTTP requests |
MAX_RETRIES | 2 | Number of retries for failed requests |
DEFAULT_DAYS | 250 | Default period if no date range is provided |
STK_DATA_PRE_URL | https://www.nasdaq.com/api/v1/historical/ | Base URL for Nasdaq API |
Sources: lib/stolgo/nasdaq.py:11-15, lib/stolgo/nasdaq.py:19
API Parameters: get_data
The primary interface for external interaction is the get_data method.
| Parameter | Type | Required | Description |
|---|---|---|---|
symbol | string | Yes | The stock ticker (e.g., "AAPL") |
start | string | No | Start date for historical data |
end | string | No | End date for historical data |
periods | integer | No | Number of days to retrieve |
dayfirst | bool | No | Date format preference (European style) |
Sources: lib/stolgo/nasdaq.py:84-125
Implementation Details
URL Construction
The NasdaqUrls class formats dates into %Y-%m-%d and constructs a RESTful URL string.
# Internal URL format
url = self.STK_DATA_PRE_URL + symbol + r"/stocks/" + start + r"/" + end
Sources: lib/stolgo/nasdaq.py:38-40
Error Handling
The integration utilizes a custom BadDataError for data validation and wraps networking calls in try-except blocks to provide descriptive error messages regarding URL construction or network connectivity. If Nasdaq returns no data for a small range, the system automatically expands the range to DEFAULT_DAYS (250) to attempt a successful retrieval.
Sources: lib/stolgo/nasdaq.py:108-116, lib/stolgo/exception.py:1-3
Summary
The Nasdaq Data Integration module provides a robust mechanism for accessing US stock market data. By managing headers, complex date ranges, and offering a recursive adjustment logic for missing data, it ensures that users receive a consistent pandas.DataFrame suitable for the library's technical analysis tools. It leverages the stolgo.request infrastructure to handle timeouts and retries, making it resilient for automated trading and backtesting workflows.