API Basics
This page covers the request and response patterns that stay consistent across tv-scraper.
Request Style
Separate exchange and symbol
For symbol-based methods, pass them as two arguments:
Output structure:
{ "status": "success", "data": {"RSI": 54.21}, "metadata": { "exchange": "NASDAQ", "symbol": "AAPL", "timeframe": "1d", "technical_indicators": ["RSI"], }, "warnings": [], "error": None, }
Use keyword arguments
Keyword arguments make the calls easier to read and reduce mistakes:
Optional lists stay as Python lists
scraper.get_news(
provider=["reuters", "tradingview"],
market_country=["US", "IN"],
market=["stock", "crypto"],
)
Naming stays snake_case
Response Envelope
Every public scraper method returns:
{ "status": "success" | "failed", "data": ..., "metadata": {...}, "warnings": [str, ...], "error": None | "message", }
What changes by method
datacan be a dict, list, orNonemetadatakeeps the call context and method-specific detailswarningsis a list of non-blocking messages (e.g. deprecations, indicator validation warnings)errorisNoneon success and a message on failure
Important nuance
Most failures return data=None, but some methods can return partial data with status="failed" when that is the intended behavior. The forecast streaming methods are the main example.
Error Handling
Error Handling
Public scraper methods return failures instead of raising data-access errors.
{ "status": "failed", "data": None, "metadata": { "exchange": "INVALID", "symbol": "AAPL", "technical_indicators": ["RSI"], }, "warnings": [], "error": "Invalid value: 'INVALID'. ...", }
wrong input
This is the wrong style for public methods.
Use snake_case and correct parameters:
Construction-Time Errors
Construction-Time Errors
Some constructor arguments are validated immediately and raise ValueError before any network activity:
- invalid
export(must be"json","csv", orNone) - invalid
timeout(must be integer between 1 and 300)
from tv_scraper import Technicals
Technicals(export="xml") # Raises ValueError
Technicals(timeout=0) # Raises ValueError
Internal Validation Helpers
If you are contributing to tv-scraper, use these BaseScraper methods for consistent validation:
| Method | Purpose |
|---|---|
self._validate_choice(val, choices) |
Check if a value is in an allowed set. |
self._validate_list(vals, choices) |
Batch check a list of values. |
self._validate_range(val, min, max) |
Check if a number is within bounds. |
self._validate_timeframe(tf) |
Standardized TradingView timeframe check. |
self._verify_symbol_exchange(exc, sym) |
Live existence check via Scanner API. |
Finding Accepted Values
When a page says an input must be from a supported list, use the exact section links: