investing-algorithm-framework 6.3.1__tar.gz → 6.4.0__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.
Files changed (206) hide show
  1. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/PKG-INFO +10 -16
  2. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/README.md +8 -15
  3. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/__init__.py +7 -2
  4. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/app.py +276 -74
  5. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/context.py +176 -23
  6. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/strategy.py +28 -3
  7. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/initialize_app.py +0 -1
  8. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/create_app.py +1 -0
  9. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/dependency_container.py +18 -10
  10. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/__init__.py +10 -3
  11. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/data_provider.py +18 -3
  12. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/__init__.py +2 -0
  13. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/backtesting/backtest_report.py +12 -2
  14. investing_algorithm_framework-6.4.0/investing_algorithm_framework/domain/models/data_source.py +21 -0
  15. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/order/order.py +14 -5
  16. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/trade/trade.py +24 -16
  17. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/trade/trade_stop_loss.py +58 -3
  18. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/trade/trade_take_profit.py +59 -4
  19. investing_algorithm_framework-6.4.0/investing_algorithm_framework/domain/order_executor.py +87 -0
  20. investing_algorithm_framework-6.4.0/investing_algorithm_framework/domain/portfolio_provider.py +89 -0
  21. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/services/portfolios/portfolio_sync_service.py +0 -6
  22. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/utils/__init__.py +2 -1
  23. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/utils/backtesting.py +63 -37
  24. investing_algorithm_framework-6.4.0/investing_algorithm_framework/domain/utils/random.py +41 -0
  25. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/download_data.py +4 -0
  26. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/__init__.py +5 -1
  27. investing_algorithm_framework-6.4.0/investing_algorithm_framework/infrastructure/data_providers/csv.py +257 -0
  28. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/order/order.py +4 -4
  29. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/order/order_metadata.py +6 -0
  30. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/portfolio/sql_portfolio.py +7 -4
  31. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/trades/trade.py +20 -17
  32. investing_algorithm_framework-6.4.0/investing_algorithm_framework/infrastructure/order_executors/__init__.py +19 -0
  33. investing_algorithm_framework-6.4.0/investing_algorithm_framework/infrastructure/order_executors/ccxt_order_executor.py +156 -0
  34. investing_algorithm_framework-6.4.0/investing_algorithm_framework/infrastructure/portfolio_providers/__init__.py +19 -0
  35. investing_algorithm_framework-6.4.0/investing_algorithm_framework/infrastructure/portfolio_providers/ccxt_portfolio_provider.py +144 -0
  36. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/repositories/order_repository.py +4 -0
  37. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/repositories/position_repository.py +4 -0
  38. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/repositories/repository.py +42 -31
  39. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/__init__.py +8 -5
  40. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/backtesting/backtest_service.py +2 -2
  41. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/market_data_source_service/data_provider_service.py +59 -0
  42. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/market_data_source_service/market_data_source_service.py +0 -5
  43. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/order_service/__init__.py +3 -1
  44. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/order_service/order_backtest_service.py +9 -13
  45. investing_algorithm_framework-6.4.0/investing_algorithm_framework/services/order_service/order_executor_lookup.py +110 -0
  46. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/order_service/order_service.py +262 -210
  47. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/portfolios/__init__.py +3 -1
  48. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/portfolios/portfolio_configuration_service.py +8 -2
  49. investing_algorithm_framework-6.4.0/investing_algorithm_framework/services/portfolios/portfolio_provider_lookup.py +108 -0
  50. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/portfolios/portfolio_service.py +42 -18
  51. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/portfolios/portfolio_sync_service.py +29 -119
  52. investing_algorithm_framework-6.4.0/investing_algorithm_framework/services/positions/__init__.py +7 -0
  53. investing_algorithm_framework-6.4.0/investing_algorithm_framework/services/positions/position_service.py +210 -0
  54. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/strategy_orchestrator_service.py +5 -3
  55. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/trade_service/trade_service.py +158 -53
  56. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/pyproject.toml +2 -1
  57. investing_algorithm_framework-6.3.1/investing_algorithm_framework/domain/order_executor.py +0 -63
  58. investing_algorithm_framework-6.3.1/investing_algorithm_framework/domain/portfolio_provider.py +0 -62
  59. investing_algorithm_framework-6.3.1/investing_algorithm_framework/domain/utils/random.py +0 -12
  60. investing_algorithm_framework-6.3.1/investing_algorithm_framework/services/position_service.py +0 -29
  61. investing_algorithm_framework-6.3.1/investing_algorithm_framework/test.py +0 -16
  62. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/LICENSE +0 -0
  63. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/__init__.py +0 -0
  64. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/algorithm.py +0 -0
  65. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/stateless/__init__.py +0 -0
  66. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/stateless/action_handlers/__init__.py +0 -0
  67. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/stateless/action_handlers/action_handler_strategy.py +0 -0
  68. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/stateless/action_handlers/check_online_handler.py +0 -0
  69. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/stateless/action_handlers/run_strategy_handler.py +0 -0
  70. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/stateless/exception_handler.py +0 -0
  71. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/task.py +0 -0
  72. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/web/__init__.py +0 -0
  73. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/web/controllers/__init__.py +0 -0
  74. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/web/controllers/orders.py +0 -0
  75. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/web/controllers/portfolio.py +0 -0
  76. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/web/controllers/positions.py +0 -0
  77. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/web/create_app.py +0 -0
  78. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/web/error_handler.py +0 -0
  79. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/web/responses.py +0 -0
  80. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/web/run_strategies.py +0 -0
  81. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/web/schemas/__init__.py +0 -0
  82. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/web/schemas/order.py +0 -0
  83. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/web/schemas/portfolio.py +0 -0
  84. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/web/schemas/position.py +0 -0
  85. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/app/web/setup_cors.py +0 -0
  86. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/__init__.py +0 -0
  87. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/cli.py +0 -0
  88. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/deploy_to_azure_function.py +0 -0
  89. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/.gitignore.template +0 -0
  90. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/app-web.py.template +0 -0
  91. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/app.py.template +0 -0
  92. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/app_azure_function.py.template +0 -0
  93. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/app_web.py.template +0 -0
  94. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/azure_function_function_app.py.template +0 -0
  95. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/azure_function_host.json.template +0 -0
  96. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/azure_function_local.settings.json.template +0 -0
  97. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/data_providers.py.template +0 -0
  98. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/env.example.template +0 -0
  99. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/env_azure_function.example.template +0 -0
  100. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/market_data_providers.py.template +0 -0
  101. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/readme.md.template +0 -0
  102. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/requirements.txt.template +0 -0
  103. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/requirements_azure_function.txt.template +0 -0
  104. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/run_backtest.py.template +0 -0
  105. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/cli/templates/strategy.py.template +0 -0
  106. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/config.py +0 -0
  107. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/constants.py +0 -0
  108. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/data_structures.py +0 -0
  109. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/decimal_parsing.py +0 -0
  110. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/exceptions.py +0 -0
  111. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/metrics/__init__.py +0 -0
  112. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/metrics/price_efficiency.py +0 -0
  113. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/app_mode.py +0 -0
  114. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/backtesting/__init__.py +0 -0
  115. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/backtesting/backtest_date_range.py +0 -0
  116. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/backtesting/backtest_position.py +0 -0
  117. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/backtesting/backtest_reports_evaluation.py +0 -0
  118. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/base_model.py +0 -0
  119. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/date_range.py +0 -0
  120. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/market/__init__.py +0 -0
  121. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/market/market_credential.py +0 -0
  122. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/market_data_type.py +0 -0
  123. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/order/__init__.py +0 -0
  124. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/order/order_side.py +0 -0
  125. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/order/order_status.py +0 -0
  126. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/order/order_type.py +0 -0
  127. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/portfolio/__init__.py +0 -0
  128. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/portfolio/portfolio.py +0 -0
  129. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/portfolio/portfolio_configuration.py +0 -0
  130. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/portfolio/portfolio_snapshot.py +0 -0
  131. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/position/__init__.py +0 -0
  132. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/position/position.py +0 -0
  133. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/position/position_snapshot.py +0 -0
  134. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/strategy_profile.py +0 -0
  135. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/time_frame.py +0 -0
  136. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/time_interval.py +0 -0
  137. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/time_unit.py +0 -0
  138. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/tracing/__init__.py +0 -0
  139. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/tracing/trace.py +0 -0
  140. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/trade/__init__.py +0 -0
  141. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/trade/trade_risk_type.py +0 -0
  142. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/trade/trade_status.py +0 -0
  143. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/trading_data_types.py +0 -0
  144. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/models/trading_time_frame.py +0 -0
  145. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/services/__init__.py +0 -0
  146. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/services/market_credential_service.py +0 -0
  147. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/services/market_data_sources.py +0 -0
  148. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/services/market_service.py +0 -0
  149. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/services/portfolios/__init__.py +0 -0
  150. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/services/rounding_service.py +0 -0
  151. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/services/state_handler.py +0 -0
  152. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/stateless_actions.py +0 -0
  153. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/strategy.py +0 -0
  154. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/utils/csv.py +0 -0
  155. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/utils/polars.py +0 -0
  156. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/utils/signatures.py +0 -0
  157. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/utils/stoppable_thread.py +0 -0
  158. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/domain/utils/synchronized.py +0 -0
  159. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/data_providers/__init__.py +0 -0
  160. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/data_providers/ccxt.py +0 -0
  161. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/database/__init__.py +0 -0
  162. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/database/sql_alchemy.py +0 -0
  163. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/__init__.py +0 -0
  164. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/decimal_parser.py +0 -0
  165. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/market_data_sources/__init__.py +0 -0
  166. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py +0 -0
  167. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py +0 -0
  168. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/market_data_sources/pandas.py +0 -0
  169. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/market_data_sources/us_treasury_yield.py +0 -0
  170. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/model_extension.py +0 -0
  171. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/order/__init__.py +0 -0
  172. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/order_trade_association.py +0 -0
  173. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/portfolio/__init__.py +0 -0
  174. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/portfolio/portfolio_snapshot.py +0 -0
  175. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/position/__init__.py +0 -0
  176. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/position/position.py +0 -0
  177. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/position/position_snapshot.py +0 -0
  178. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/trades/__init__.py +0 -0
  179. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/trades/trade_stop_loss.py +0 -0
  180. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/models/trades/trade_take_profit.py +0 -0
  181. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/repositories/__init__.py +0 -0
  182. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/repositories/order_metadata_repository.py +0 -0
  183. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/repositories/portfolio_repository.py +0 -0
  184. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/repositories/portfolio_snapshot_repository.py +0 -0
  185. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/repositories/position_snapshot_repository.py +0 -0
  186. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/repositories/trade_repository.py +0 -0
  187. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/repositories/trade_stop_loss_repository.py +0 -0
  188. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/repositories/trade_take_profit_repository.py +0 -0
  189. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/services/__init__.py +0 -0
  190. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/services/azure/__init__.py +0 -0
  191. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/services/azure/state_handler.py +0 -0
  192. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/services/market_service/__init__.py +0 -0
  193. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/services/market_service/ccxt_market_service.py +0 -0
  194. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/services/performance_service/__init__.py +0 -0
  195. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/services/performance_service/backtest_performance_service.py +0 -0
  196. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/infrastructure/services/performance_service/performance_service.py +0 -0
  197. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/backtesting/__init__.py +0 -0
  198. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/configuration_service.py +0 -0
  199. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/market_credential_service.py +0 -0
  200. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/market_data_source_service/__init__.py +0 -0
  201. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/market_data_source_service/backtest_market_data_source_service.py +0 -0
  202. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/portfolios/backtest_portfolio_service.py +0 -0
  203. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/portfolios/portfolio_snapshot_service.py +0 -0
  204. {investing_algorithm_framework-6.3.1/investing_algorithm_framework/services → investing_algorithm_framework-6.4.0/investing_algorithm_framework/services/positions}/position_snapshot_service.py +0 -0
  205. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/repository_service.py +0 -0
  206. {investing_algorithm_framework-6.3.1 → investing_algorithm_framework-6.4.0}/investing_algorithm_framework/services/trade_service/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: investing-algorithm-framework
3
- Version: 6.3.1
3
+ Version: 6.4.0
4
4
  Summary: A framework for creating trading bots
5
5
  Author: MDUYN
6
6
  Requires-Python: >=3.10
@@ -22,6 +22,7 @@ Requires-Dist: dependency-injector (>=4.40.0)
22
22
  Requires-Dist: jupyter (>=1.0.0)
23
23
  Requires-Dist: marshmallow (>=3.5.0)
24
24
  Requires-Dist: polars[numpy,pandas] (>=0.20.10)
25
+ Requires-Dist: pyarrow (>=19.0.1)
25
26
  Requires-Dist: python-dateutil (>=2.8.2)
26
27
  Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
27
28
  Requires-Dist: schedule (>=1.1.0)
@@ -104,9 +105,9 @@ The following example connects to Binance and buys BTC every 2 hours.
104
105
  import logging.config
105
106
  from dotenv import load_dotenv
106
107
 
107
- from investing_algorithm_framework import create_app, PortfolioConfiguration, \
108
- TimeUnit, CCXTOHLCVMarketDataSource, Context, CCXTTickerMarketDataSource, \
109
- MarketCredential, DEFAULT_LOGGING_CONFIG, Algorithm, Context
108
+ from investing_algorithm_framework import create_app, TimeUnit, \
109
+ CCXTOHLCVMarketDataSource, CCXTTickerMarketDataSource, \
110
+ DEFAULT_LOGGING_CONFIG, Algorithm, Context
110
111
 
111
112
  load_dotenv()
112
113
  logging.config.dictConfig(DEFAULT_LOGGING_CONFIG)
@@ -125,17 +126,10 @@ bitvavo_btc_eur_ticker = CCXTTickerMarketDataSource(
125
126
  market="BITVAVO",
126
127
  symbol="BTC/EUR",
127
128
  )
128
- app = create_app()
129
-
130
- # Bitvavo market credentials are read from .env file, or you can
131
- # set them manually as params
132
- app.add_market_credential(MarketCredential(market="bitvavo"))
133
- app.add_portfolio_configuration(
134
- PortfolioConfiguration(
135
- market="bitvavo", trading_symbol="EUR", initial_balance=40
136
- )
137
- )
138
129
 
130
+ app = create_app()
131
+ # Registered bitvavo market, credentials are read from .env file by default
132
+ app.add_market(market="BITVAVO", trading_symbol="EUR", initial_balance=100)
139
133
  algorithm = Algorithm(name="test_algorithm")
140
134
 
141
135
  # Define a strategy for the algorithm that will run every 10 seconds
@@ -370,8 +364,8 @@ This will ensure that interested parties can give valuable feedback on the featu
370
364
 
371
365
  ## 📬 Support
372
366
 
373
- * Slack Community
374
- * Reddit Community
367
+ * [Reddit Community](https://www.reddit.com/r/InvestingBots/)
368
+ * [Discord Community](https://discord.gg/dQsRmGZP")
375
369
 
376
370
 
377
371
  ## 🏆 Acknowledgements
@@ -72,9 +72,9 @@ 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, PortfolioConfiguration, \
76
- TimeUnit, CCXTOHLCVMarketDataSource, Context, CCXTTickerMarketDataSource, \
77
- MarketCredential, DEFAULT_LOGGING_CONFIG, Algorithm, Context
75
+ from investing_algorithm_framework import create_app, TimeUnit, \
76
+ CCXTOHLCVMarketDataSource, CCXTTickerMarketDataSource, \
77
+ DEFAULT_LOGGING_CONFIG, Algorithm, Context
78
78
 
79
79
  load_dotenv()
80
80
  logging.config.dictConfig(DEFAULT_LOGGING_CONFIG)
@@ -93,17 +93,10 @@ bitvavo_btc_eur_ticker = CCXTTickerMarketDataSource(
93
93
  market="BITVAVO",
94
94
  symbol="BTC/EUR",
95
95
  )
96
- app = create_app()
97
-
98
- # Bitvavo market credentials are read from .env file, or you can
99
- # set them manually as params
100
- app.add_market_credential(MarketCredential(market="bitvavo"))
101
- app.add_portfolio_configuration(
102
- PortfolioConfiguration(
103
- market="bitvavo", trading_symbol="EUR", initial_balance=40
104
- )
105
- )
106
96
 
97
+ app = create_app()
98
+ # Registered bitvavo market, credentials are read from .env file by default
99
+ app.add_market(market="BITVAVO", trading_symbol="EUR", initial_balance=100)
107
100
  algorithm = Algorithm(name="test_algorithm")
108
101
 
109
102
  # Define a strategy for the algorithm that will run every 10 seconds
@@ -338,8 +331,8 @@ This will ensure that interested parties can give valuable feedback on the featu
338
331
 
339
332
  ## 📬 Support
340
333
 
341
- * Slack Community
342
- * Reddit Community
334
+ * [Reddit Community](https://www.reddit.com/r/InvestingBots/)
335
+ * [Discord Community](https://discord.gg/dQsRmGZP")
343
336
 
344
337
 
345
338
  ## 🏆 Acknowledgements
@@ -12,7 +12,8 @@ from investing_algorithm_framework.domain import ApiException, \
12
12
  load_backtest_report, BacktestDateRange, convert_polars_to_pandas, \
13
13
  DateRange, get_backtest_report, DEFAULT_LOGGING_CONFIG, \
14
14
  BacktestReport, TradeStatus, MarketDataType, TradeRiskType, \
15
- APPLICATION_DIRECTORY
15
+ APPLICATION_DIRECTORY, pretty_print_orders, pretty_print_trades, \
16
+ pretty_print_positions, DataSource
16
17
  from investing_algorithm_framework.infrastructure import \
17
18
  CCXTOrderBookMarketDataSource, CCXTOHLCVMarketDataSource, \
18
19
  CCXTTickerMarketDataSource, CSVOHLCVMarketDataSource, \
@@ -77,5 +78,9 @@ __all__ = [
77
78
  "TradeRiskType",
78
79
  "Context",
79
80
  "APPLICATION_DIRECTORY",
80
- "download"
81
+ "download",
82
+ "pretty_print_orders",
83
+ "pretty_print_trades",
84
+ "pretty_print_positions",
85
+ "DataSource",
81
86
  ]
@@ -19,9 +19,10 @@ from investing_algorithm_framework.domain import DATABASE_NAME, TimeUnit, \
19
19
  BACKTESTING_START_DATE, BACKTESTING_END_DATE, BacktestReport, \
20
20
  APP_MODE, MarketCredential, AppMode, BacktestDateRange, \
21
21
  DATABASE_DIRECTORY_NAME, BACKTESTING_INITIAL_AMOUNT, \
22
- MarketDataSource, APPLICATION_DIRECTORY, PortfolioConfiguration
22
+ MarketDataSource, APPLICATION_DIRECTORY, PortfolioConfiguration, \
23
+ PortfolioProvider, OrderExecutor, ImproperlyConfigured
23
24
  from investing_algorithm_framework.infrastructure import setup_sqlalchemy, \
24
- create_all_tables
25
+ create_all_tables, CCXTOrderExecutor, CCXTPortfolioProvider
25
26
  from investing_algorithm_framework.services import OrderBacktestService, \
26
27
  BacktestMarketDataSourceService, BacktestPortfolioService, \
27
28
  MarketDataSourceService, MarketCredentialService
@@ -211,6 +212,8 @@ class App:
211
212
  None
212
213
  """
213
214
  logger.info("Initializing app")
215
+ self._initialize_default_order_executors()
216
+ self._initialize_default_portfolio_providers()
214
217
 
215
218
  if self.algorithm is None:
216
219
  raise OperationalException("No algorithm registered")
@@ -240,18 +243,20 @@ class App:
240
243
  portfolio_snap_service = self.container \
241
244
  .portfolio_snapshot_service()
242
245
  market_cred_service = self.container.market_credential_service()
246
+ portfolio_provider_lookup = \
247
+ self.container.portfolio_provider_lookup()
243
248
  # Override the portfolio service with the backtest
244
249
  # portfolio service
245
250
  self.container.portfolio_service.override(
246
251
  BacktestPortfolioService(
247
252
  configuration_service=configuration_service,
248
253
  market_credential_service=market_cred_service,
249
- market_service=self.container.market_service(),
250
254
  position_service=self.container.position_service(),
251
255
  order_service=self.container.order_service(),
252
256
  portfolio_repository=self.container.portfolio_repository(),
253
257
  portfolio_configuration_service=portfolio_conf_service,
254
- portfolio_snapshot_service=portfolio_snap_service
258
+ portfolio_snapshot_service=portfolio_snap_service,
259
+ portfolio_provider_lookup=portfolio_provider_lookup
255
260
  )
256
261
  )
257
262
 
@@ -284,7 +289,7 @@ class App:
284
289
  OrderBacktestService(
285
290
  trade_service=self.container.trade_service(),
286
291
  order_repository=self.container.order_repository(),
287
- position_repository=self.container.position_repository(),
292
+ position_service=self.container.position_service(),
288
293
  portfolio_repository=self.container.portfolio_repository(),
289
294
  portfolio_configuration_service=portfolio_conf_service,
290
295
  portfolio_snapshot_service=portfolio_snap_service,
@@ -350,74 +355,7 @@ class App:
350
355
  )
351
356
  self._initialize_web()
352
357
 
353
- # Initialize all portfolios that are registered
354
- portfolio_configuration_service = self.container \
355
- .portfolio_configuration_service()
356
- portfolio_service = self.container.portfolio_service()
357
-
358
- # Throw an error if no portfolios are configured
359
- if portfolio_configuration_service.count() == 0:
360
- raise OperationalException("No portfolios configured")
361
-
362
- if Environment.BACKTEST.equals(config[ENVIRONMENT]):
363
- initial_backtest_amount = config.get(
364
- BACKTESTING_INITIAL_AMOUNT, None
365
- )
366
-
367
- for portfolio_configuration \
368
- in portfolio_configuration_service.get_all():
369
-
370
- if not portfolio_service.exists(
371
- {"identifier": portfolio_configuration.identifier}
372
- ):
373
- portfolio = (
374
- portfolio_service.create_portfolio_from_configuration(
375
- portfolio_configuration,
376
- initial_amount=initial_backtest_amount,
377
- )
378
- )
379
- else:
380
- synced_portfolios = []
381
-
382
- for portfolio_configuration \
383
- in portfolio_configuration_service.get_all():
384
-
385
- if not portfolio_service.exists(
386
- {"identifier": portfolio_configuration.identifier}
387
- ):
388
- portfolio = portfolio_service\
389
- .create_portfolio_from_configuration(
390
- portfolio_configuration
391
- )
392
-
393
- portfolios = portfolio_service.get_all()
394
-
395
- for portfolio in portfolios:
396
-
397
- if portfolio not in synced_portfolios:
398
- self.sync(portfolio)
399
-
400
- def sync(self, portfolio):
401
- """
402
- Sync the portfolio with the exchange. This method should be called
403
- before running the algorithm. It syncs the portfolio with the
404
- exchange by syncing the unallocated balance, positions, orders, and
405
- trades.
406
-
407
- Args:
408
- portfolio (Portfolio): The portfolio to sync
409
-
410
- Returns:
411
- None
412
- """
413
- logger.info(f"Syncing portfolio {portfolio.identifier}")
414
- portfolio_sync_service = self.container.portfolio_sync_service()
415
-
416
- # Sync unallocated balance
417
- portfolio_sync_service.sync_unallocated(portfolio)
418
-
419
- # Sync all orders from exchange with current order history
420
- portfolio_sync_service.sync_orders(portfolio)
358
+ self._initialize_portfolios()
421
359
 
422
360
  def run(
423
361
  self,
@@ -476,7 +414,7 @@ class App:
476
414
  self._state_handler.load(config[RESOURCE_DIRECTORY])
477
415
 
478
416
  self.initialize()
479
- logger.info("Initialization complete")
417
+ logger.info("App initialization complete")
480
418
 
481
419
  # Run all on_initialize hooks
482
420
  for hook in self._on_initialize_hooks:
@@ -1020,3 +958,267 @@ class App:
1020
958
  secret_key=secret_key
1021
959
  )
1022
960
  self.add_market_credential(market_credential)
961
+
962
+ def add_order_executor(self, order_executor):
963
+ """
964
+ Function to add an order executor to the app. The order executor
965
+ should be an instance of OrderExecutor.
966
+
967
+ Args:
968
+ order_executor: Instance of OrderExecutor
969
+
970
+ Returns:
971
+ None
972
+ """
973
+
974
+ if inspect.isclass(order_executor):
975
+ order_executor = order_executor()
976
+
977
+ if not isinstance(order_executor, OrderExecutor):
978
+ raise OperationalException(
979
+ "Order executor should be an instance of OrderExecutor"
980
+ )
981
+
982
+ order_executor_lookup = self.container.order_executor_lookup()
983
+ order_executor_lookup.add_order_executor(
984
+ order_executor=order_executor
985
+ )
986
+
987
+ def get_order_executors(self):
988
+ """
989
+ Function to get all order executors from the app. This method
990
+ should be called when you want to get all order executors.
991
+
992
+ Returns:
993
+ List of OrderExecutor instances
994
+ """
995
+ order_executor_lookup = self.container.order_executor_lookup()
996
+ return order_executor_lookup.get_all()
997
+
998
+ def add_portfolio_provider(self, portfolio_provider):
999
+ """
1000
+ Function to add a portfolio provider to the app. The portfolio
1001
+ provider should be an instance of PortfolioProvider.
1002
+
1003
+ Args:
1004
+ portfolio_provider: Instance of PortfolioProvider
1005
+
1006
+ Returns:
1007
+ None
1008
+ """
1009
+
1010
+ if inspect.isclass(portfolio_provider):
1011
+ portfolio_provider = portfolio_provider()
1012
+
1013
+ if not isinstance(portfolio_provider, PortfolioProvider):
1014
+ raise OperationalException(
1015
+ "Portfolio provider should be an instance of "
1016
+ "PortfolioProvider"
1017
+ )
1018
+
1019
+ portfolio_provider_lookup = self.container.portfolio_provider_lookup()
1020
+ portfolio_provider_lookup.add_portfolio_provider(
1021
+ portfolio_provider=portfolio_provider
1022
+ )
1023
+
1024
+ def get_portfolio_providers(self):
1025
+ """
1026
+ Function to get all portfolio providers from the app. This method
1027
+ should be called when you want to get all portfolio providers.
1028
+
1029
+ Returns:
1030
+ List of PortfolioProvider instances
1031
+ """
1032
+ portfolio_provider_lookup = self.container.portfolio_provider_lookup()
1033
+ return portfolio_provider_lookup.get_all()
1034
+
1035
+ def _initialize_portfolios(self):
1036
+ """
1037
+ Function to initialize the portfolios. This function will
1038
+ first check if the app is running in backtest mode or not. If it is
1039
+ running in backtest mode, it will create the portfolios with the
1040
+ initial amount specified in the config. If it is not running in
1041
+ backtest mode, it will check if there are
1042
+
1043
+ """
1044
+ logger.info("Initializing portfolios")
1045
+ config = self.config
1046
+
1047
+ portfolio_configuration_service = self.container \
1048
+ .portfolio_configuration_service()
1049
+ portfolio_service = self.container.portfolio_service()
1050
+
1051
+ # Throw an error if no portfolios are configured
1052
+ if portfolio_configuration_service.count() == 0:
1053
+ raise OperationalException("No portfolios configured")
1054
+
1055
+ if Environment.BACKTEST.equals(config[ENVIRONMENT]):
1056
+ logger.info("Setting up backtest portfolios")
1057
+ initial_backtest_amount = config.get(
1058
+ BACKTESTING_INITIAL_AMOUNT, None
1059
+ )
1060
+
1061
+ for portfolio_configuration \
1062
+ in portfolio_configuration_service.get_all():
1063
+
1064
+ if not portfolio_service.exists(
1065
+ {"identifier": portfolio_configuration.identifier}
1066
+ ):
1067
+ portfolio = (
1068
+ portfolio_service.create_portfolio_from_configuration(
1069
+ portfolio_configuration,
1070
+ initial_amount=initial_backtest_amount,
1071
+ )
1072
+ )
1073
+ else:
1074
+ # Check if there are already existing portfolios
1075
+ portfolios = portfolio_service.get_all()
1076
+ portfolio_configurations = portfolio_configuration_service\
1077
+ .get_all()
1078
+
1079
+ if len(portfolios) > 0:
1080
+
1081
+ # Check if there are matching portfolio configurations
1082
+ for portfolio in portfolios:
1083
+ logger.info(
1084
+ f"Checking if there is an matching portfolio "
1085
+ "configuration "
1086
+ f"for portfolio {portfolio.identifier}"
1087
+ )
1088
+ portfolio_configuration = \
1089
+ portfolio_configuration_service.get(
1090
+ portfolio.market
1091
+ )
1092
+
1093
+ if portfolio_configuration is None:
1094
+ raise ImproperlyConfigured(
1095
+ f"No matching portfolio configuration found for "
1096
+ f"existing portfolio {portfolio.market}, "
1097
+ f"please make sure that you have configured your "
1098
+ f"app with the right portfolio configurations "
1099
+ f"for the existing portfolios."
1100
+ f"If you want to create a new portfolio, please "
1101
+ f"remove the existing database (WARNING!!: this "
1102
+ f"will remove all existing history of your "
1103
+ f"trading bot.)"
1104
+ )
1105
+
1106
+ # Check if the portfolio configuration is still inline
1107
+ # with the initial balance
1108
+
1109
+ if portfolio_configuration.initial_balance != \
1110
+ portfolio.initial_balance:
1111
+ logger.warning(
1112
+ "The initial balance of the portfolio "
1113
+ "configuration is different from the existing "
1114
+ "portfolio. Checking if the existing portfolio "
1115
+ "can be updated..."
1116
+ )
1117
+
1118
+ portfolio_provider_lookup = \
1119
+ self.container.portfolio_provider_lookup()
1120
+ # Register a portfolio provider for the portfolio
1121
+ portfolio_provider_lookup \
1122
+ .register_portfolio_provider_for_market(
1123
+ portfolio_configuration.market
1124
+ )
1125
+ initial_balance = portfolio_configuration\
1126
+ .initial_balance
1127
+
1128
+ if initial_balance != portfolio.initial_balance:
1129
+ raise ImproperlyConfigured(
1130
+ "The initial balance of the portfolio "
1131
+ "configuration is different then that of "
1132
+ "the existing portfolio. Please make sure "
1133
+ "that the initial balance of the portfolio "
1134
+ "configuration is the same as that of the "
1135
+ "existing portfolio. "
1136
+ f"Existing portfolio initial balance: "
1137
+ f"{portfolio.initial_balance}, "
1138
+ f"Portfolio configuration initial balance: "
1139
+ f"{portfolio_configuration.initial_balance}"
1140
+ "If this is intentional, please remove "
1141
+ "the database and re-run the app. "
1142
+ "WARNING!!: this will remove all existing "
1143
+ "history of your trading bot."
1144
+ )
1145
+
1146
+ portfolio_provider_lookup = \
1147
+ self.container.portfolio_provider_lookup()
1148
+ order_executor_lookup = self.container.order_executor_lookup()
1149
+
1150
+ # Register portfolio providers and order executors
1151
+ for portfolio_configuration in portfolio_configurations:
1152
+
1153
+ # Register a portfolio provider for the portfolio
1154
+ portfolio_provider_lookup\
1155
+ .register_portfolio_provider_for_market(
1156
+ portfolio_configuration.market
1157
+ )
1158
+
1159
+ # Register an order executor for the portfolio
1160
+ order_executor_lookup.register_order_executor_for_market(
1161
+ portfolio_configuration.market
1162
+ )
1163
+
1164
+ market_credential = \
1165
+ self._market_credential_service.get(
1166
+ portfolio_configuration.market
1167
+ )
1168
+
1169
+ if market_credential is None:
1170
+ raise ImproperlyConfigured(
1171
+ f"No market credential found for existing "
1172
+ f"portfolio {portfolio_configuration.market} "
1173
+ "with market "
1174
+ "Cannot initialize portfolio configuration."
1175
+ )
1176
+
1177
+ if not portfolio_service.exists(
1178
+ {"identifier": portfolio_configuration.identifier}
1179
+ ):
1180
+ portfolio_service.create_portfolio_from_configuration(
1181
+ portfolio_configuration
1182
+ )
1183
+
1184
+ logger.info("Portfolio configurations complete")
1185
+ logger.info("Syncing portfolios")
1186
+ portfolio_service = self.container.portfolio_service()
1187
+ portfolio_sync_service = self.container.portfolio_sync_service()
1188
+
1189
+ for portfolio in portfolio_service.get_all():
1190
+ logger.info(f"Syncing portfolio {portfolio.identifier}")
1191
+ portfolio_sync_service.sync_unallocated(portfolio)
1192
+ portfolio_sync_service.sync_orders(portfolio)
1193
+
1194
+ def _initialize_default_portfolio_providers(self):
1195
+ """
1196
+ Function to initialize the default portfolio providers.
1197
+ This function will create a default portfolio provider for
1198
+ each market that is configured in the app. The default portfolio
1199
+ provider will be used to create portfolios for the app.
1200
+
1201
+ Returns:
1202
+ None
1203
+ """
1204
+ logger.info("Adding default portfolio providers")
1205
+ portfolio_provider_lookup = self.container.portfolio_provider_lookup()
1206
+ portfolio_provider_lookup.add_portfolio_provider(
1207
+ CCXTPortfolioProvider()
1208
+ )
1209
+
1210
+ def _initialize_default_order_executors(self):
1211
+ """
1212
+ Function to initialize the default order executors.
1213
+ This function will create a default order executor for
1214
+ each market that is configured in the app. The default order
1215
+ executor will be used to create orders for the app.
1216
+
1217
+ Returns:
1218
+ None
1219
+ """
1220
+ logger.info("Adding default order executors")
1221
+ order_executor_lookup = self.container.order_executor_lookup()
1222
+ order_executor_lookup.add_order_executor(
1223
+ CCXTOrderExecutor()
1224
+ )