Add historical OHLCV data extractor #55
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request: Add Historical OHLCV Data Extractor
Summary
This PR adds a new
OHLCVExtractorclass to thetradingview_scraperpackage, providing a convenient way to fetch historical OHLCV (Open, High, Low, Close, Volume) data from TradingView with customizable timeframes and bar counts.Motivation
While the existing
RealTimeDataclass provides excellent streaming capabilities for real-time data, there was no straightforward way to fetch historical OHLCV data on-demand without maintaining a persistent WebSocket connection. This extractor fills that gap by providing:Changes
New Files
tradingview_scraper/symbols/stream/ohlcv_extractor.pyOHLCVExtractorclassRealTimeDatawith on-demand data fetching capabilitiesget_ohlcv_json()andget_multiple_ohlcv_json()examples/ohlcv_extractor_example.pyModified Files
tradingview_scraper/symbols/stream/__init__.pyOHLCVExtractor,get_ohlcv_json, andget_multiple_ohlcv_jsonREADME.mdFeatures
Core Functionality
Data Format
Each bar includes:
Error Handling
Usage Examples
Quick Start
Multiple Symbols
Advanced Usage
Technical Details
Architecture
The
OHLCVExtractorclass:RealTimeDataclassfinallyblocksDesign Decisions
Per-Request Connections: Each data request creates a new WebSocket connection to ensure clean state and avoid connection reuse issues.
Timeout Protection: Default 30-second timeout prevents hanging requests, with configurable override.
Debug Mode: Logging is silenced by default for production use, but can be enabled for troubleshooting.
Convenience Functions: Top-level functions (
get_ohlcv_json,get_multiple_ohlcv_json) provide simple interfaces for common use cases.Testing
The integration has been tested with:
Backward Compatibility
This PR is fully backward compatible:
streammoduleDocumentation
Future Enhancements
Potential future improvements:
Checklist
Related Issues
This PR addresses the need for on-demand historical OHLCV data extraction, complementing the existing real-time streaming capabilities.