System Architecture Overview
Relevant source files
The following files were used as context for generating this wiki page:
Stolgo is a Price Action Trading Analysis Library designed to automate price action rules and facilitate backtesting for traders. Unlike libraries focused solely on technical indicators, Stolgo provides a structured framework for analyzing market data through support/resistance levels, candlestick patterns, trends, and breakouts.
Sources: README.md:1-12
The system architecture is divided into three primary layers: the Data Acquisition Layer, which interfaces with external brokers and exchanges; the Utility and Request Layer, which handles network communication and data formatting; and the Analysis Layer, which implements trading logic and pattern recognition.
Core Component Architecture
The library is structured as a modular Python package. It utilizes pandas for data manipulation and requests for network communication.
Analysis Layer
This layer contains the business logic for price action analysis. It processes historical or intraday data (typically in the form of pandas DataFrames) to identify specific market conditions.
| Component | Class/Module | Description |
|---|---|---|
| Candlestick Analysis | CandleStick | Identifies patterns like Bullish Engulfing, Hammer, Inverted Hammer, and Doji. |
| Breakout Logic | Breakout | Detects periods of consolidation and subsequent price breakouts or breakdowns. |
| Trend Analysis | Trend | Evaluates price direction over specified periods (e.g., Giant Uptrend/Downtrend). |
Sources: lib/stolgo/candlestick.py:3-85, lib/stolgo/breakout.py:4-87, lib/stolgo/trend.py:5-83
Data Acquisition Layer
Stolgo integrates with multiple data providers to fetch financial records. It includes specialized handlers for Nasdaq and Samco (a broker).
The diagram above illustrates the flow of data from external sources through provider-specific classes into a unified DataFrame format.
Sources: lib/stolgo/nasdaq.py:50-136, lib/stolgo/samco.py:90-181
Connectivity and Request Management
Network requests are managed through a centralized system that supports both standard HTTP sessions and specialized cURL-based requests for cloud environments.
Request Handling Logic
The RequestUrl class utilizes requests.Session with custom retry logic and timeout adapters. For environments requiring low-level execution, the Curl class provides a wrapper around system curl commands using subprocess.
- TimeoutHTTPAdapter: Extends
HTTPAdapterto enforce default timeouts (5 seconds). - Retry Policy: Implements backoff factors and status forcelists (429, 500, 502, 503, 504) to ensure robust data fetching.
Sources: lib/stolgo/request.py:10-108
Data Resampling and Formatting
To ensure consistency across different data sources, the helper module provides utilities for date range calculation and OHLC (Open, High, Low, Close, Volume) resampling.
OHLC Resampling Flow
When data is fetched with a specific interval (e.g., 5-minute candles from 1-minute data), the system applies a standard aggregation mapping.
Technical Specifications
Key Configuration Parameters
| Parameter | Default Value | Description |
|---|---|---|
DEFAULT_TIMEOUT | 5 | Connection timeout in seconds. |
MAX_RETRIES | 2 | Number of retries for failed HTTP requests. |
DEFAULT_DAYS | 250 | Default period for historical data if unspecified. |
Sources: lib/stolgo/nasdaq.py:12-16, lib/stolgo/request.py:7-8, lib/stolgo/helper.py:7-8
Dependency Graph
The system relies on several external libraries for its core functionality, defined in the project configuration:
- pandas: Used for all time-series data storage and resampling.
- requests: Primary driver for API communication.
- beautifulsoup4 / lxml: Used for parsing HTML/XML data when applicable.
- openpyxl: Enables Excel-based data exports (e.g., option chains).
Sources: setup.py:23-30
Conclusion
Stolgo provides a specialized architecture for price action trading by decoupling data acquisition from analysis logic. Its use of standard pandas DataFrames as the primary data exchange format allows it to be highly interoperable with other quantitative finance tools, while its robust request management layer ensures reliable data retrieval from varied exchange APIs.
Sources: README.md:14-20, lib/stolgo/request.py:80-108