investing-algorithm-framework 6.5.2__tar.gz → 6.5.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/PKG-INFO +4 -8
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/README.md +3 -7
- investing_algorithm_framework-6.5.4/investing_algorithm_framework/app/algorithm/__init__.py +7 -0
- investing_algorithm_framework-6.5.4/investing_algorithm_framework/app/algorithm/algorithm.py +275 -0
- investing_algorithm_framework-6.5.4/investing_algorithm_framework/app/algorithm/algorithm_factory.py +107 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/app.py +533 -313
- investing_algorithm_framework-6.5.4/investing_algorithm_framework/app/app_hook.py +28 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/context.py +4 -4
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/stateless/action_handlers/__init__.py +4 -2
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/stateless/action_handlers/action_handler_strategy.py +1 -1
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/stateless/action_handlers/check_online_handler.py +1 -1
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/stateless/action_handlers/run_strategy_handler.py +13 -7
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/cli.py +3 -1
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/app-web.py.template +1 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/app.py.template +1 -7
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/app_azure_function.py.template +1 -7
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/app_web.py.template +1 -7
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/dependency_container.py +6 -2
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/order_executor.py +6 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/portfolio_provider.py +10 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/services/market_data_sources.py +4 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/download_data.py +5 -2
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py +11 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/backtesting/backtest_service.py +34 -112
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/market_data_source_service/backtest_market_data_source_service.py +7 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/market_data_source_service/market_data_source_service.py +23 -5
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/portfolios/portfolio_sync_service.py +0 -1
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/strategy_orchestrator_service.py +33 -31
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/pyproject.toml +2 -1
- investing_algorithm_framework-6.5.2/investing_algorithm_framework/app/algorithm.py +0 -383
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/LICENSE +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/stateless/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/stateless/exception_handler.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/strategy.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/task.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/web/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/web/controllers/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/web/controllers/orders.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/web/controllers/portfolio.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/web/controllers/positions.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/web/create_app.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/web/error_handler.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/web/responses.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/web/run_strategies.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/web/schemas/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/web/schemas/order.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/web/schemas/portfolio.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/web/schemas/position.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/app/web/setup_cors.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/deploy_to_azure_function.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/initialize_app.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/.gitignore.template +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/azure_function_function_app.py.template +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/azure_function_host.json.template +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/azure_function_local.settings.json.template +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/data_providers.py.template +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/env.example.template +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/env_azure_function.example.template +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/market_data_providers.py.template +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/readme.md.template +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/requirements.txt.template +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/requirements_azure_function.txt.template +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/run_backtest.py.template +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/cli/templates/strategy.py.template +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/create_app.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/config.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/constants.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/data_provider.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/data_structures.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/decimal_parsing.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/exceptions.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/metrics/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/metrics/price_efficiency.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/app_mode.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/backtesting/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/backtesting/backtest_date_range.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/backtesting/backtest_position.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/backtesting/backtest_report.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/backtesting/backtest_reports_evaluation.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/base_model.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/data_source.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/date_range.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/market/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/market/market_credential.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/market_data_type.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/order/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/order/order.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/order/order_side.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/order/order_status.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/order/order_type.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/portfolio/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/portfolio/portfolio.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/portfolio/portfolio_configuration.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/portfolio/portfolio_snapshot.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/position/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/position/position.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/position/position_snapshot.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/strategy_profile.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/time_frame.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/time_interval.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/time_unit.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/tracing/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/tracing/trace.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/trade/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/trade/trade.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/trade/trade_risk_type.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/trade/trade_status.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/trade/trade_stop_loss.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/trade/trade_take_profit.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/trading_data_types.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/models/trading_time_frame.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/services/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/services/market_credential_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/services/market_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/services/portfolios/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/services/portfolios/portfolio_sync_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/services/rounding_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/services/state_handler.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/stateless_actions.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/strategy.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/utils/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/utils/backtesting.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/utils/csv.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/utils/polars.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/utils/random.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/utils/signatures.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/utils/stoppable_thread.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/domain/utils/synchronized.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/data_providers/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/data_providers/ccxt.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/data_providers/csv.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/database/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/database/sql_alchemy.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/decimal_parser.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/market_data_sources/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/market_data_sources/pandas.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/market_data_sources/us_treasury_yield.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/model_extension.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/order/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/order/order.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/order/order_metadata.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/order_trade_association.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/portfolio/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/portfolio/portfolio_snapshot.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/portfolio/sql_portfolio.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/position/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/position/position.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/position/position_snapshot.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/trades/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/trades/trade.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/trades/trade_stop_loss.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/models/trades/trade_take_profit.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/order_executors/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/order_executors/ccxt_order_executor.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/portfolio_providers/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/portfolio_providers/ccxt_portfolio_provider.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/repositories/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/repositories/order_metadata_repository.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/repositories/order_repository.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/repositories/portfolio_repository.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/repositories/portfolio_snapshot_repository.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/repositories/position_repository.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/repositories/position_snapshot_repository.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/repositories/repository.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/repositories/trade_repository.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/repositories/trade_stop_loss_repository.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/repositories/trade_take_profit_repository.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/services/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/services/azure/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/services/azure/state_handler.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/services/market_service/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/services/market_service/ccxt_market_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/services/performance_service/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/services/performance_service/backtest_performance_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/infrastructure/services/performance_service/performance_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/backtesting/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/configuration_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/market_credential_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/market_data_source_service/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/market_data_source_service/data_provider_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/order_service/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/order_service/order_backtest_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/order_service/order_executor_lookup.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/order_service/order_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/portfolios/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/portfolios/backtest_portfolio_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/portfolios/portfolio_configuration_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/portfolios/portfolio_provider_lookup.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/portfolios/portfolio_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/portfolios/portfolio_snapshot_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/positions/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/positions/position_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/positions/position_snapshot_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/repository_service.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/trade_service/__init__.py +0 -0
- {investing_algorithm_framework-6.5.2 → investing_algorithm_framework-6.5.4}/investing_algorithm_framework/services/trade_service/trade_service.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: investing-algorithm-framework
|
|
3
|
-
Version: 6.5.
|
|
3
|
+
Version: 6.5.4
|
|
4
4
|
Summary: A framework for creating trading bots
|
|
5
5
|
Author: MDUYN
|
|
6
6
|
Requires-Python: >=3.10
|
|
@@ -105,9 +105,8 @@ The following example connects to Binance and buys BTC every 2 hours.
|
|
|
105
105
|
import logging.config
|
|
106
106
|
from dotenv import load_dotenv
|
|
107
107
|
|
|
108
|
-
from investing_algorithm_framework import create_app, TimeUnit, \
|
|
109
|
-
CCXTOHLCVMarketDataSource, CCXTTickerMarketDataSource,
|
|
110
|
-
DEFAULT_LOGGING_CONFIG, Algorithm, Context
|
|
108
|
+
from investing_algorithm_framework import create_app, TimeUnit, Context, \
|
|
109
|
+
CCXTOHLCVMarketDataSource, CCXTTickerMarketDataSource, DEFAULT_LOGGING_CONFIG
|
|
111
110
|
|
|
112
111
|
load_dotenv()
|
|
113
112
|
logging.config.dictConfig(DEFAULT_LOGGING_CONFIG)
|
|
@@ -130,10 +129,9 @@ bitvavo_btc_eur_ticker = CCXTTickerMarketDataSource(
|
|
|
130
129
|
app = create_app()
|
|
131
130
|
# Registered bitvavo market, credentials are read from .env file by default
|
|
132
131
|
app.add_market(market="BITVAVO", trading_symbol="EUR", initial_balance=100)
|
|
133
|
-
algorithm = Algorithm(name="test_algorithm")
|
|
134
132
|
|
|
135
133
|
# Define a strategy for the algorithm that will run every 10 seconds
|
|
136
|
-
@
|
|
134
|
+
@app.strategy(
|
|
137
135
|
time_unit=TimeUnit.SECOND,
|
|
138
136
|
interval=10,
|
|
139
137
|
market_data_sources=[bitvavo_btc_eur_ticker, bitvavo_btc_eur_ohlcv_2h]
|
|
@@ -148,8 +146,6 @@ def perform_strategy(context: Context, market_data: dict):
|
|
|
148
146
|
open_trades = context.get_open_trades()
|
|
149
147
|
closed_trades = context.get_closed_trades()
|
|
150
148
|
|
|
151
|
-
app.add_algorithm(algorithm)
|
|
152
|
-
|
|
153
149
|
if __name__ == "__main__":
|
|
154
150
|
app.run()
|
|
155
151
|
```
|
|
@@ -72,9 +72,8 @@ The following example connects to Binance and buys BTC every 2 hours.
|
|
|
72
72
|
import logging.config
|
|
73
73
|
from dotenv import load_dotenv
|
|
74
74
|
|
|
75
|
-
from investing_algorithm_framework import create_app, TimeUnit, \
|
|
76
|
-
CCXTOHLCVMarketDataSource, CCXTTickerMarketDataSource,
|
|
77
|
-
DEFAULT_LOGGING_CONFIG, Algorithm, Context
|
|
75
|
+
from investing_algorithm_framework import create_app, TimeUnit, Context, \
|
|
76
|
+
CCXTOHLCVMarketDataSource, CCXTTickerMarketDataSource, DEFAULT_LOGGING_CONFIG
|
|
78
77
|
|
|
79
78
|
load_dotenv()
|
|
80
79
|
logging.config.dictConfig(DEFAULT_LOGGING_CONFIG)
|
|
@@ -97,10 +96,9 @@ bitvavo_btc_eur_ticker = CCXTTickerMarketDataSource(
|
|
|
97
96
|
app = create_app()
|
|
98
97
|
# Registered bitvavo market, credentials are read from .env file by default
|
|
99
98
|
app.add_market(market="BITVAVO", trading_symbol="EUR", initial_balance=100)
|
|
100
|
-
algorithm = Algorithm(name="test_algorithm")
|
|
101
99
|
|
|
102
100
|
# Define a strategy for the algorithm that will run every 10 seconds
|
|
103
|
-
@
|
|
101
|
+
@app.strategy(
|
|
104
102
|
time_unit=TimeUnit.SECOND,
|
|
105
103
|
interval=10,
|
|
106
104
|
market_data_sources=[bitvavo_btc_eur_ticker, bitvavo_btc_eur_ohlcv_2h]
|
|
@@ -115,8 +113,6 @@ def perform_strategy(context: Context, market_data: dict):
|
|
|
115
113
|
open_trades = context.get_open_trades()
|
|
116
114
|
closed_trades = context.get_closed_trades()
|
|
117
115
|
|
|
118
|
-
app.add_algorithm(algorithm)
|
|
119
|
-
|
|
120
116
|
if __name__ == "__main__":
|
|
121
117
|
app.run()
|
|
122
118
|
```
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
import logging
|
|
3
|
+
import re
|
|
4
|
+
from typing import List
|
|
5
|
+
|
|
6
|
+
from investing_algorithm_framework.app.app_hook import AppHook
|
|
7
|
+
from investing_algorithm_framework.app.strategy import TradingStrategy
|
|
8
|
+
from investing_algorithm_framework.domain import OperationalException, \
|
|
9
|
+
MarketDataSource
|
|
10
|
+
|
|
11
|
+
logger = logging.getLogger("investing_algorithm_framework")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Algorithm:
|
|
15
|
+
"""
|
|
16
|
+
Class to represent an algorithm. An algorithm is a collection of
|
|
17
|
+
strategies that are executed in a specific order.
|
|
18
|
+
|
|
19
|
+
Attributes:
|
|
20
|
+
_name: The name of the algorithm. It should be a string and
|
|
21
|
+
can only contain letters and numbers.
|
|
22
|
+
_description: The description of the algorithm. It should be a string.
|
|
23
|
+
_strategies: A list of strategies that are part of the algorithm.
|
|
24
|
+
_tasks: A list of tasks that are part of the algorithm.
|
|
25
|
+
_data_sources: A list of data sources that are part of the algorithm.
|
|
26
|
+
_on_strategy_run_hooks: A list of hooks that will be called when a
|
|
27
|
+
"""
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
name: str = None,
|
|
31
|
+
description: str = None,
|
|
32
|
+
strategy=None,
|
|
33
|
+
strategies=None,
|
|
34
|
+
tasks: List = None,
|
|
35
|
+
data_sources: List[MarketDataSource] = None,
|
|
36
|
+
on_strategy_run_hooks=None
|
|
37
|
+
):
|
|
38
|
+
self._name = name
|
|
39
|
+
self._context = {}
|
|
40
|
+
self._description = None
|
|
41
|
+
|
|
42
|
+
if description is not None:
|
|
43
|
+
self._description = description
|
|
44
|
+
|
|
45
|
+
self._strategies = []
|
|
46
|
+
self._tasks = []
|
|
47
|
+
self._data_sources = []
|
|
48
|
+
self._on_strategy_run_hooks = []
|
|
49
|
+
|
|
50
|
+
if data_sources is not None:
|
|
51
|
+
self._data_sources = data_sources
|
|
52
|
+
|
|
53
|
+
if strategies is not None:
|
|
54
|
+
self.strategies = strategies
|
|
55
|
+
|
|
56
|
+
if tasks is not None:
|
|
57
|
+
self.tasks = tasks
|
|
58
|
+
|
|
59
|
+
if strategy is not None:
|
|
60
|
+
self.add_strategy(strategy, throw_exception=True)
|
|
61
|
+
|
|
62
|
+
if on_strategy_run_hooks is not None:
|
|
63
|
+
for hook in on_strategy_run_hooks:
|
|
64
|
+
self.add_on_strategy_run_hook(hook)
|
|
65
|
+
|
|
66
|
+
@staticmethod
|
|
67
|
+
def _validate_name(name):
|
|
68
|
+
"""
|
|
69
|
+
Function to validate the name of the algorithm. This function
|
|
70
|
+
will check if the name of the algorithm is a string and raise
|
|
71
|
+
an exception if it is not.
|
|
72
|
+
|
|
73
|
+
Name can only contain letters, numbers
|
|
74
|
+
|
|
75
|
+
Parameters:
|
|
76
|
+
name: The name of the algorithm
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
None
|
|
80
|
+
"""
|
|
81
|
+
if not isinstance(name, str):
|
|
82
|
+
raise OperationalException(
|
|
83
|
+
"The name of the algorithm must be a string"
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
pattern = re.compile(r"^[a-zA-Z0-9]*$")
|
|
87
|
+
|
|
88
|
+
if not pattern.match(name):
|
|
89
|
+
raise OperationalException(
|
|
90
|
+
"The name of the algorithm can only contain" +
|
|
91
|
+
" letters and numbers"
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
illegal_chars = r"[\/:*?\"<>|]"
|
|
95
|
+
|
|
96
|
+
if re.search(illegal_chars, name):
|
|
97
|
+
raise OperationalException(
|
|
98
|
+
f"Illegal characters detected in algorithm: {name}. "
|
|
99
|
+
f"Illegal characters: / \\ : * ? \" < > |"
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def name(self):
|
|
104
|
+
return self._name
|
|
105
|
+
|
|
106
|
+
@name.setter
|
|
107
|
+
def name(self, name):
|
|
108
|
+
Algorithm._validate_name(name)
|
|
109
|
+
self._name = name
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def data_sources(self):
|
|
113
|
+
return self._data_sources
|
|
114
|
+
|
|
115
|
+
@data_sources.setter
|
|
116
|
+
def data_sources(self, data_sources):
|
|
117
|
+
self._data_sources = data_sources
|
|
118
|
+
|
|
119
|
+
@property
|
|
120
|
+
def description(self):
|
|
121
|
+
"""
|
|
122
|
+
Function to get the description of the algorithm
|
|
123
|
+
"""
|
|
124
|
+
return self._description
|
|
125
|
+
|
|
126
|
+
@property
|
|
127
|
+
def strategies(self):
|
|
128
|
+
return self._strategies
|
|
129
|
+
|
|
130
|
+
@property
|
|
131
|
+
def on_strategy_run_hooks(self):
|
|
132
|
+
return self._on_strategy_run_hooks
|
|
133
|
+
|
|
134
|
+
@strategies.setter
|
|
135
|
+
def strategies(self, strategies):
|
|
136
|
+
|
|
137
|
+
for strategy in strategies:
|
|
138
|
+
self.add_strategy(strategy)
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def tasks(self):
|
|
142
|
+
return self._tasks
|
|
143
|
+
|
|
144
|
+
@tasks.setter
|
|
145
|
+
def tasks(self, tasks):
|
|
146
|
+
|
|
147
|
+
for task in tasks:
|
|
148
|
+
self.add_task(task)
|
|
149
|
+
|
|
150
|
+
def get_strategy(self, strategy_id):
|
|
151
|
+
for strategy in self._strategies:
|
|
152
|
+
if strategy.worker_id == strategy_id:
|
|
153
|
+
return strategy
|
|
154
|
+
|
|
155
|
+
return None
|
|
156
|
+
|
|
157
|
+
def get_strategies(self):
|
|
158
|
+
|
|
159
|
+
if self._strategies is None:
|
|
160
|
+
raise OperationalException(
|
|
161
|
+
"No strategies have been added to the algorithm"
|
|
162
|
+
)
|
|
163
|
+
return self._strategies
|
|
164
|
+
|
|
165
|
+
def add_strategy(self, strategy, throw_exception=True) -> None:
|
|
166
|
+
"""
|
|
167
|
+
Function to add a strategy to the algorithm. The strategy should be an
|
|
168
|
+
instance of TradingStrategy or a subclass based on the TradingStrategy
|
|
169
|
+
class.
|
|
170
|
+
|
|
171
|
+
Args:
|
|
172
|
+
strategy: Instance of TradingStrategy
|
|
173
|
+
throw_exception: Flag to allow for throwing an exception when
|
|
174
|
+
the provided strategy is not inline with what the application
|
|
175
|
+
expects.
|
|
176
|
+
|
|
177
|
+
Returns:
|
|
178
|
+
None
|
|
179
|
+
"""
|
|
180
|
+
|
|
181
|
+
if inspect.isclass(strategy):
|
|
182
|
+
|
|
183
|
+
if not issubclass(strategy, TradingStrategy):
|
|
184
|
+
raise OperationalException(
|
|
185
|
+
"The strategy must be a subclass of TradingStrategy"
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
strategy = strategy()
|
|
189
|
+
|
|
190
|
+
if not isinstance(strategy, TradingStrategy):
|
|
191
|
+
|
|
192
|
+
if throw_exception:
|
|
193
|
+
raise OperationalException(
|
|
194
|
+
"Strategy should be an instance of TradingStrategy"
|
|
195
|
+
)
|
|
196
|
+
else:
|
|
197
|
+
return
|
|
198
|
+
|
|
199
|
+
has_duplicates = False
|
|
200
|
+
|
|
201
|
+
for i in range(len(self._strategies)):
|
|
202
|
+
for j in range(i + 1, len(self._strategies)):
|
|
203
|
+
if self._strategies[i].worker_id == strategy.worker_id:
|
|
204
|
+
has_duplicates = True
|
|
205
|
+
break
|
|
206
|
+
|
|
207
|
+
if has_duplicates:
|
|
208
|
+
raise OperationalException(
|
|
209
|
+
"Can't add strategy, there already exists a strategy "
|
|
210
|
+
"with the same id in the algorithm"
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
if strategy.market_data_sources is not None:
|
|
214
|
+
self.add_data_sources(strategy.market_data_sources)
|
|
215
|
+
|
|
216
|
+
self._strategies.append(strategy)
|
|
217
|
+
|
|
218
|
+
def add_task(self, task):
|
|
219
|
+
if inspect.isclass(task):
|
|
220
|
+
task = task()
|
|
221
|
+
|
|
222
|
+
self._tasks.append(task)
|
|
223
|
+
|
|
224
|
+
def add_data_source(self, data_source) -> None:
|
|
225
|
+
"""
|
|
226
|
+
Function to add a data source to the app. The data source should
|
|
227
|
+
be an instance of DataSource.
|
|
228
|
+
|
|
229
|
+
Args:
|
|
230
|
+
data_source: Instance of DataSource
|
|
231
|
+
|
|
232
|
+
Returns:
|
|
233
|
+
None
|
|
234
|
+
"""
|
|
235
|
+
if inspect.isclass(data_source):
|
|
236
|
+
if not issubclass(data_source, MarketDataSource):
|
|
237
|
+
raise OperationalException(
|
|
238
|
+
"Data source should be an instance of MarketDataSource"
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
data_source = data_source()
|
|
242
|
+
|
|
243
|
+
self.data_sources.append(data_source)
|
|
244
|
+
|
|
245
|
+
def add_data_sources(self, data_sources) -> None:
|
|
246
|
+
"""
|
|
247
|
+
Function to add a list of data sources to the app. The data sources
|
|
248
|
+
should be instances of DataSource.
|
|
249
|
+
|
|
250
|
+
Args:
|
|
251
|
+
data_sources: List of DataSource
|
|
252
|
+
|
|
253
|
+
Returns:
|
|
254
|
+
None
|
|
255
|
+
"""
|
|
256
|
+
for data_source in data_sources:
|
|
257
|
+
self.add_data_source(data_source)
|
|
258
|
+
|
|
259
|
+
def add_on_strategy_run_hook(self, app_hook):
|
|
260
|
+
"""
|
|
261
|
+
Function to add a hook that will be called when a strategy is run.
|
|
262
|
+
|
|
263
|
+
Args:
|
|
264
|
+
app_hook: The hook function to be added.
|
|
265
|
+
"""
|
|
266
|
+
# Check if the app_hook inherits from AppHook
|
|
267
|
+
if inspect.isclass(app_hook) and not issubclass(app_hook, AppHook):
|
|
268
|
+
raise OperationalException(
|
|
269
|
+
"App hook should be an instance of AppHook"
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
if inspect.isclass(app_hook):
|
|
273
|
+
app_hook = app_hook()
|
|
274
|
+
|
|
275
|
+
self._on_strategy_run_hooks.append(app_hook)
|
investing_algorithm_framework-6.5.4/investing_algorithm_framework/app/algorithm/algorithm_factory.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from .algorithm import Algorithm
|
|
3
|
+
from investing_algorithm_framework.domain import OperationalException
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def validate_algorithm_name(name, illegal_chars=r"[\/:*?\"<>|]"):
|
|
7
|
+
"""
|
|
8
|
+
Validate an algorithm name for illegal characters and throw an
|
|
9
|
+
exception if any are found.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
name (str): The name to validate.
|
|
13
|
+
illegal_chars (str): A regex pattern for characters considered
|
|
14
|
+
illegal (default: r"[/:*?\"<>|]").
|
|
15
|
+
|
|
16
|
+
Raises:
|
|
17
|
+
ValueError: If illegal characters are found in the filename.
|
|
18
|
+
"""
|
|
19
|
+
if re.search(illegal_chars, name):
|
|
20
|
+
raise OperationalException(
|
|
21
|
+
f"Illegal characters detected in filename: {name}. "
|
|
22
|
+
f"Illegal characters: {illegal_chars}"
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class AlgorithmFactory:
|
|
27
|
+
"""
|
|
28
|
+
Factory class for creating an algorithm instance.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
@staticmethod
|
|
32
|
+
def create_algorithm_name(algorithm):
|
|
33
|
+
"""
|
|
34
|
+
Create a name for the algorithm based on its
|
|
35
|
+
strategies.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
algorithm (Algorithm): Instance of Algorithm.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
str: Name of the algorithm.
|
|
42
|
+
"""
|
|
43
|
+
first_strategy = algorithm.strategies[0] \
|
|
44
|
+
if algorithm.strategies else None
|
|
45
|
+
|
|
46
|
+
if first_strategy is not None:
|
|
47
|
+
return f"{first_strategy.__class__.__name__}"
|
|
48
|
+
|
|
49
|
+
return "DefaultAlgorithm"
|
|
50
|
+
|
|
51
|
+
@staticmethod
|
|
52
|
+
def create_algorithm(
|
|
53
|
+
name=None,
|
|
54
|
+
algorithm=None,
|
|
55
|
+
strategy=None,
|
|
56
|
+
strategies=None,
|
|
57
|
+
tasks=None,
|
|
58
|
+
on_strategy_run_hooks=None,
|
|
59
|
+
data_sources=None
|
|
60
|
+
) -> Algorithm:
|
|
61
|
+
"""
|
|
62
|
+
Create an instance of the specified algorithm type.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
name (str): Name of the algorithm.
|
|
66
|
+
algorithm (Algorithm): Instance of Algorithm to be used.
|
|
67
|
+
strategy (TradingStrategy): Single TradingStrategy instance.
|
|
68
|
+
strategies (list): List of TradingStrategy instances.
|
|
69
|
+
tasks (list): List of Task instances.
|
|
70
|
+
on_strategy_run_hooks (list): List of hooks to be called
|
|
71
|
+
when a strategy is run.
|
|
72
|
+
data_sources (list): List of MarketDataSource instances.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
Algorithm: Instance of Algorithm.
|
|
76
|
+
"""
|
|
77
|
+
name = name
|
|
78
|
+
strategies = strategies or []
|
|
79
|
+
tasks = tasks or []
|
|
80
|
+
on_strategy_run_hooks = on_strategy_run_hooks or []
|
|
81
|
+
data_sources = data_sources or []
|
|
82
|
+
|
|
83
|
+
if algorithm is not None:
|
|
84
|
+
|
|
85
|
+
for task in tasks:
|
|
86
|
+
algorithm.add_task(task)
|
|
87
|
+
|
|
88
|
+
for app_hook in on_strategy_run_hooks:
|
|
89
|
+
algorithm.add_on_strategy_run_hook(app_hook)
|
|
90
|
+
|
|
91
|
+
return algorithm
|
|
92
|
+
|
|
93
|
+
algorithm = Algorithm(
|
|
94
|
+
name=name,
|
|
95
|
+
strategy=strategy,
|
|
96
|
+
strategies=strategies,
|
|
97
|
+
tasks=tasks,
|
|
98
|
+
on_strategy_run_hooks=on_strategy_run_hooks,
|
|
99
|
+
data_sources=data_sources
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
if algorithm.name is None:
|
|
103
|
+
algorithm.name = AlgorithmFactory.create_algorithm_name(algorithm)
|
|
104
|
+
|
|
105
|
+
# Validate the algorithm name
|
|
106
|
+
validate_algorithm_name(algorithm.name)
|
|
107
|
+
return algorithm
|