Stolgo Overview
Relevant source files
The following files were used as context for generating this wiki page:
Stolgo is a Python-based Price Action Trading Analysis Library designed to automate price action rules and facilitate backtesting. Unlike many libraries that focus on technical indicators like MACD or RSI, Stolgo specializes in parameters based directly on price movement, including support/resistance, candlestick patterns, trends, and breakouts.
The library provides a structured way to fetch financial data from various sources (such as Nasdaq and Samco) and apply technical analysis modules to that data. It leverages pandas for data manipulation and requests for API interactions.
Sources: README.md:1-13, setup.py:23-31
System Architecture
Stolgo is organized into three primary layers: the Data Acquisition layer, the Helper/Utility layer, and the Analysis layer.
Data Flow Architecture
The following diagram illustrates how data flows from external providers through Stolgo's request handling into the analysis modules.
The system uses specialized classes for each data provider to handle URL construction and response parsing, while common utilities manage date formatting and data resampling.
Sources: lib/stolgo/request.py:73-81, lib/stolgo/nasdaq.py:46-52, lib/stolgo/samco.py:78-83, lib/stolgo/helper.py:65-71
Data Acquisition Modules
Stolgo supports multiple data sources, primarily focusing on Nasdaq for US stocks and Samco for Indian markets.
Nasdaq Integration
The Nasdaq class provides historical stock data by constructing specific URLs for the Nasdaq API. It includes logic to adjust date ranges automatically if the requested period is not immediately available.
| Method | Description |
|---|---|
get_data | Primary API to fetch historical data as a pandas DataFrame. |
__get_data_adjusted | Internal logic to fill missing periods by extending date ranges. |
Sources: lib/stolgo/nasdaq.py:46-126
Samco Integration
The Samco module provides access to both historical and intraday data via the Stocknote API. It requires authentication (User ID, Password, and Year of Birth) to establish a session token.
| Component | Description |
|---|---|
SamcoUrl | Manages endpoint construction for historical, intraday, and option chain data. |
Samco | Main class handling login, session management, and data retrieval. |
get_optionchain | Retrieves option chain data for a given symbol. |
Sources: lib/stolgo/samco.py:16-166
Technical Analysis Modules
The core of Stolgo's value proposition is its ability to identify price action patterns within the fetched data.
Candlestick Pattern Recognition
The CandleStick class identifies specific candle formations by comparing OHLC (Open, High, Low, Close) values.
Key patterns supported:
- Bullish Engulfing: Current bullish candle completely covers the previous bearish candle's body.
- Hammer/Inverted Hammer: Defined by specific ratios of body to upper/lower wicks.
- Doji: Identified by a very small body relative to the total candle length.
Sources: lib/stolgo/candlestick.py:5-75
Breakout and Consolidation
The Breakout module identifies periods where price is trading within a tight range (consolidation) and detects when price moves outside those boundaries.
# Example: Check for breakout
from stolgo.breakout import Breakout
breakout_test = Breakout(periods=13, percentage=2)
is_be = breakout_test.is_breaking_out(dfs)
Sources: lib/stolgo/breakout.py:4-70, README.md:52-56
Trend Analysis
The Trend class provides methods to identify sustained directional movements. is_giant_uptrend and is_giant_downtrend require a sequence of candles to consistently close higher (or lower) than their predecessors over a specified period.
Sources: lib/stolgo/trend.py:8-70
Infrastructure and Utilities
Request Handling
Stolgo implements a robust request system in request.py that includes:
- TimeoutHTTPAdapter: Custom adapter to ensure requests do not hang indefinitely.
- Retry Logic: Uses
urllib3.util.Retryto handle transient errors (429, 500, 502, 503, 504). - Curl Support: A
Curlclass that usessubprocessto execute system-level curl commands, used whencloud_modeis enabled.
Sources: lib/stolgo/request.py:11-106
Helper Functions
The helper.py module provides critical date manipulation utilities:
get_date_range: Calculates start and end dates based on periods or provided date strings.get_data_resample: Standardizes DataFrames to specific timeframes (e.g., converting 1-minute data to 5-minute data) using OHLC aggregation.
Sources: lib/stolgo/helper.py:45-91
Conclusion
Stolgo provides a specialized framework for price action traders to bridge the gap between manual charting and automated analysis. By combining reliable data retrieval with a dedicated suite of candlestick and trend detection algorithms, it serves as a foundation for building complex backtesting strategies and automated trading signals.
Sources: README.md:1-10