API Conventions
This document defines the standards for the tv-scraper public API.
Input Parameters
Symbol Identification
All scrapers accept exchange and symbol as separate string parameters:
Field Selection
Optional field selection uses a list of strings:
Sorting
Sorting follows a consistent pattern:
sort_order defaults to "desc" when not specified.
Naming Convention
All parameters use snake_case:
# Correct
scraper.get_technicals(export_result=True, export_type="json", sort_by="change")
# Wrong — never use camelCase
scraper.get_technicals(exportResult=True)
Output Format
Response Envelope
Every public scraper method returns a standardized response dict:
{
"status": "success", # or "failed"
"data": [...], # payload (list, dict, or None on failure)
"metadata": { # contextual info
"symbol": "AAPL",
"exchange": "NASDAQ",
"total": 25
},
"error": None # error message string, or None on success
}
Success Response
statusis always"success"datacontains the requested payloaderroris alwaysNonemetadatacontains relevant context (symbol, exchange, counts, etc.)
Error Response
statusis always"failed"datais alwaysNoneerrorcontains a descriptive error messagemetadatamay contain partial context
Error Handling
Scraper Methods Never Raise
Public scraper methods never raise exceptions. All errors are caught internally and returned as error responses:
result = scraper.get_technicals(exchange="INVALID", symbol="AAPL")
# Returns: {"status": "failed", "data": None, "error": "Invalid exchange: ...", "metadata": {}}
Validators Raise Internally
The DataValidator raises ValidationError for invalid input. BaseScraper subclasses catch these and convert them to error responses — exceptions never escape to user code.
Type Hints
All functions and methods have 100% type hints:
def get_technicals(
self,
exchange: str,
symbol: str,
fields: Optional[List[str]] = None,
sort_by: Optional[str] = None,
sort_order: str = "desc",
) -> Dict[str, Any]:
...
Docstrings
All public classes and methods use Google-style docstrings: