Schemas
Pydantic configuration schemas
Pydantic schema models for TheStrat configuration validation.
This module provides comprehensive validation schemas that replace all manual validation logic in the Factory class. Models use Pydantic v2 features for maximum performance, type safety, and detailed error reporting.
Classes:
Name | Description |
---|---|
AggregationConfig |
Complete configuration for aggregation component with market-aware settings. |
AssetClassConfig |
Configuration for a specific asset class with comprehensive market metadata. |
FactoryConfig |
Root configuration for Factory.create_all method with complete pipeline setup. |
GapDetectionConfig |
Configuration for gap detection with comprehensive threshold documentation. |
IndicatorSchema |
Complete Indicator Schema |
IndicatorsConfig |
Complete configuration for indicators component with per-timeframe settings. |
SchemaDocGenerator |
Generate comprehensive documentation from Pydantic schemas. |
SwingPointsConfig |
Configuration for swing point detection with comprehensive parameter documentation. |
TimeframeConfig |
Configuration and validation for timeframes with comprehensive metadata. |
TimeframeItemConfig |
Configuration for a single timeframe item with flexible timeframe targeting. |
AggregationConfig
Bases: BaseModel
Complete configuration for aggregation component with market-aware settings.
Methods:
Name | Description |
---|---|
apply_asset_class_defaults |
Apply AssetClassConfig defaults for timezone, hour_boundary, and session_start. |
validate_and_expand_target_timeframes |
Validate target_timeframes field and expand 'all' keyword. |
apply_asset_class_defaults
classmethod
Apply AssetClassConfig defaults for timezone, hour_boundary, and session_start.
Source code in thestrat/schemas.py
validate_and_expand_target_timeframes
classmethod
Validate target_timeframes field and expand 'all' keyword.
This Pydantic field validator is automatically called when AggregationConfig is instantiated. It validates individual timeframes and expands ['all'] to all supported timeframes.
Source code in thestrat/schemas.py
AssetClassConfig
Bases: BaseModel
Configuration for a specific asset class with comprehensive market metadata.
Methods:
Name | Description |
---|---|
get_config |
Get configuration for specific asset class. |
get_config
classmethod
get_config(asset_class: str) -> AssetClassConfig
FactoryConfig
Bases: BaseModel
Root configuration for Factory.create_all method with complete pipeline setup.
Methods:
Name | Description |
---|---|
validate_configuration_consistency |
Validate consistency between aggregation and indicators configurations. |
validate_configuration_consistency
Validate consistency between aggregation and indicators configurations.
Source code in thestrat/schemas.py
GapDetectionConfig
Bases: BaseModel
Configuration for gap detection with comprehensive threshold documentation.
IndicatorSchema
Bases: BaseModel
Complete Indicator Schema
Defines all columns that are created by TheStrat processing pipeline. All columns are required as the indicators component creates them all.
Methods:
Name | Description |
---|---|
get_all_input_columns |
Get list of all input columns (required + optional). |
get_column_categories |
Get columns organized by functional categories. |
get_column_descriptions |
Get descriptions for all possible DataFrame columns. |
get_optional_input_columns |
Get list of optional input columns based on schema definition. |
get_polars_dtypes |
Get Polars data types for all DataFrame columns. |
get_required_input_columns |
Get list of required input columns based on schema definition. |
validate_dataframe |
Validate input DataFrame columns and data types against IndicatorSchema input requirements. |
get_all_input_columns
classmethod
Get list of all input columns (required + optional).
Returns:
Type | Description |
---|---|
list[str]
|
List of all input column names |
Source code in thestrat/schemas.py
get_column_categories
classmethod
Get columns organized by functional categories.
Dynamically extracts categories from the IndicatorSchema metadata.
Returns:
Type | Description |
---|---|
dict[str, list[str]]
|
Dictionary mapping category names to lists of column names |
Source code in thestrat/schemas.py
get_column_descriptions
classmethod
Get descriptions for all possible DataFrame columns.
Returns:
Type | Description |
---|---|
dict[str, str]
|
Dictionary mapping column names to their descriptions |
Source code in thestrat/schemas.py
get_optional_input_columns
classmethod
Get list of optional input columns based on schema definition.
Returns:
Type | Description |
---|---|
list[str]
|
List of column names that are optional for input data |
Source code in thestrat/schemas.py
get_polars_dtypes
classmethod
Get Polars data types for all DataFrame columns.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Dictionary mapping column names to their Polars data types |
Source code in thestrat/schemas.py
get_required_input_columns
classmethod
Get list of required input columns based on schema definition.
Returns:
Type | Description |
---|---|
list[str]
|
List of column names that are required for input data |
Source code in thestrat/schemas.py
validate_dataframe
classmethod
Validate input DataFrame columns and data types against IndicatorSchema input requirements.
Automatically converts Pandas DataFrames to Polars for consistent validation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
Polars or Pandas DataFrame to validate |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Dictionary with validation results including missing/extra columns, type issues, |
dict[str, Any]
|
and the converted Polars DataFrame if conversion occurred |
Source code in thestrat/schemas.py
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 |
|
IndicatorsConfig
Bases: BaseModel
Complete configuration for indicators component with per-timeframe settings.
SchemaDocGenerator
Generate comprehensive documentation from Pydantic schemas.
Methods:
Name | Description |
---|---|
export_json_schemas |
Export JSON schemas for all models (useful for OpenAPI/AsyncAPI generation). |
generate_all_model_docs |
Generate documentation for all schema models. |
generate_complete_documentation |
Generate complete markdown documentation for all schema models. |
generate_field_docs |
Extract comprehensive field documentation from a Pydantic model. |
generate_json_schema |
Generate JSON Schema for a Pydantic model with all metadata. |
generate_markdown_table |
Generate a markdown table for a Pydantic model's fields. |
export_json_schemas
staticmethod
Export JSON schemas for all models (useful for OpenAPI/AsyncAPI generation).
Returns:
Type | Description |
---|---|
dict[str, dict[str, Any]]
|
Dictionary mapping model names to their JSON schemas |
Source code in thestrat/schemas.py
generate_all_model_docs
staticmethod
Generate documentation for all schema models.
Returns:
Type | Description |
---|---|
dict[str, dict[str, Any]]
|
Dictionary mapping model names to their complete documentation |
Source code in thestrat/schemas.py
generate_complete_documentation
staticmethod
Generate complete markdown documentation for all schema models.
Returns:
Type | Description |
---|---|
str
|
Complete markdown documentation string |
Source code in thestrat/schemas.py
generate_field_docs
staticmethod
Extract comprehensive field documentation from a Pydantic model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
type[BaseModel]
|
Pydantic model class to document |
required |
Returns:
Type | Description |
---|---|
dict[str, dict[str, Any]]
|
Dictionary mapping field names to their documentation metadata |
Source code in thestrat/schemas.py
generate_json_schema
staticmethod
Generate JSON Schema for a Pydantic model with all metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
type[BaseModel]
|
Pydantic model class |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
JSON Schema dictionary with enhanced metadata |
Source code in thestrat/schemas.py
generate_markdown_table
staticmethod
Generate a markdown table for a Pydantic model's fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
type[BaseModel]
|
Pydantic model class to document |
required |
Returns:
Type | Description |
---|---|
str
|
Markdown table string |
Source code in thestrat/schemas.py
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 |
|
SwingPointsConfig
Bases: BaseModel
Configuration for swing point detection with comprehensive parameter documentation.
TimeframeConfig
Bases: BaseModel
Configuration and validation for timeframes with comprehensive metadata.
Methods:
Name | Description |
---|---|
get_optimal_source_timeframe |
Get optimal source timeframe for aggregating to target. |
get_polars_format |
Get the Polars format for a timeframe. |
validate_timeframe |
Validate that the timeframe is supported (strict mode only). |
get_optimal_source_timeframe
classmethod
get_optimal_source_timeframe(
target_timeframe: str, available_timeframes: list[str]
) -> str | None
Get optimal source timeframe for aggregating to target.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_timeframe
|
str
|
Target timeframe to aggregate to |
required |
available_timeframes
|
list[str]
|
List of available source timeframes |
required |
Returns:
Type | Description |
---|---|
str | None
|
Optimal source timeframe or None if target already exists or no valid source |
Source code in thestrat/schemas.py
get_polars_format
classmethod
Get the Polars format for a timeframe.
validate_timeframe
classmethod
TimeframeItemConfig
Bases: BaseModel
Configuration for a single timeframe item with flexible timeframe targeting.
Methods:
Name | Description |
---|---|
validate_timeframe_combinations |
Validate that 'all' is not mixed with specific timeframes. |
validate_timeframe_combinations
Validate that 'all' is not mixed with specific timeframes.