investing-algorithm-framework 3.7.0__py3-none-any.whl → 7.19.15__py3-none-any.whl

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.

Potentially problematic release.


This version of investing-algorithm-framework might be problematic. Click here for more details.

Files changed (256) hide show
  1. investing_algorithm_framework/__init__.py +168 -45
  2. investing_algorithm_framework/app/__init__.py +32 -1
  3. investing_algorithm_framework/app/algorithm/__init__.py +7 -0
  4. investing_algorithm_framework/app/algorithm/algorithm.py +239 -0
  5. investing_algorithm_framework/app/algorithm/algorithm_factory.py +114 -0
  6. investing_algorithm_framework/app/analysis/__init__.py +15 -0
  7. investing_algorithm_framework/app/analysis/backtest_data_ranges.py +121 -0
  8. investing_algorithm_framework/app/analysis/backtest_utils.py +107 -0
  9. investing_algorithm_framework/app/analysis/permutation.py +116 -0
  10. investing_algorithm_framework/app/analysis/ranking.py +297 -0
  11. investing_algorithm_framework/app/app.py +1933 -589
  12. investing_algorithm_framework/app/app_hook.py +28 -0
  13. investing_algorithm_framework/app/context.py +1725 -0
  14. investing_algorithm_framework/app/eventloop.py +590 -0
  15. investing_algorithm_framework/app/reporting/__init__.py +27 -0
  16. investing_algorithm_framework/app/reporting/ascii.py +921 -0
  17. investing_algorithm_framework/app/reporting/backtest_report.py +349 -0
  18. investing_algorithm_framework/app/reporting/charts/__init__.py +19 -0
  19. investing_algorithm_framework/app/reporting/charts/entry_exist_signals.py +66 -0
  20. investing_algorithm_framework/app/reporting/charts/equity_curve.py +37 -0
  21. investing_algorithm_framework/app/reporting/charts/equity_curve_drawdown.py +74 -0
  22. investing_algorithm_framework/app/reporting/charts/line_chart.py +11 -0
  23. investing_algorithm_framework/app/reporting/charts/monthly_returns_heatmap.py +70 -0
  24. investing_algorithm_framework/app/reporting/charts/ohlcv_data_completeness.py +51 -0
  25. investing_algorithm_framework/app/reporting/charts/rolling_sharp_ratio.py +79 -0
  26. investing_algorithm_framework/app/reporting/charts/yearly_returns_barchart.py +55 -0
  27. investing_algorithm_framework/app/reporting/generate.py +185 -0
  28. investing_algorithm_framework/app/reporting/tables/__init__.py +11 -0
  29. investing_algorithm_framework/app/reporting/tables/key_metrics_table.py +217 -0
  30. investing_algorithm_framework/app/reporting/tables/stop_loss_table.py +0 -0
  31. investing_algorithm_framework/app/reporting/tables/time_metrics_table.py +80 -0
  32. investing_algorithm_framework/app/reporting/tables/trade_metrics_table.py +147 -0
  33. investing_algorithm_framework/app/reporting/tables/trades_table.py +75 -0
  34. investing_algorithm_framework/app/reporting/tables/utils.py +29 -0
  35. investing_algorithm_framework/app/reporting/templates/report_template.html.j2 +154 -0
  36. investing_algorithm_framework/app/stateless/action_handlers/__init__.py +4 -2
  37. investing_algorithm_framework/app/stateless/action_handlers/action_handler_strategy.py +1 -1
  38. investing_algorithm_framework/app/stateless/action_handlers/check_online_handler.py +1 -1
  39. investing_algorithm_framework/app/stateless/action_handlers/run_strategy_handler.py +14 -7
  40. investing_algorithm_framework/app/strategy.py +664 -84
  41. investing_algorithm_framework/app/task.py +5 -3
  42. investing_algorithm_framework/app/web/__init__.py +2 -1
  43. investing_algorithm_framework/app/web/create_app.py +4 -2
  44. investing_algorithm_framework/cli/__init__.py +0 -0
  45. investing_algorithm_framework/cli/cli.py +226 -0
  46. investing_algorithm_framework/cli/deploy_to_aws_lambda.py +501 -0
  47. investing_algorithm_framework/cli/deploy_to_azure_function.py +718 -0
  48. investing_algorithm_framework/cli/initialize_app.py +603 -0
  49. investing_algorithm_framework/cli/templates/.gitignore.template +178 -0
  50. investing_algorithm_framework/cli/templates/app.py.template +18 -0
  51. investing_algorithm_framework/cli/templates/app_aws_lambda_function.py.template +48 -0
  52. investing_algorithm_framework/cli/templates/app_azure_function.py.template +14 -0
  53. investing_algorithm_framework/cli/templates/app_web.py.template +18 -0
  54. investing_algorithm_framework/cli/templates/aws_lambda_dockerfile.template +22 -0
  55. investing_algorithm_framework/cli/templates/aws_lambda_dockerignore.template +92 -0
  56. investing_algorithm_framework/cli/templates/aws_lambda_readme.md.template +110 -0
  57. investing_algorithm_framework/cli/templates/aws_lambda_requirements.txt.template +2 -0
  58. investing_algorithm_framework/cli/templates/azure_function_function_app.py.template +65 -0
  59. investing_algorithm_framework/cli/templates/azure_function_host.json.template +15 -0
  60. investing_algorithm_framework/cli/templates/azure_function_local.settings.json.template +8 -0
  61. investing_algorithm_framework/cli/templates/azure_function_requirements.txt.template +3 -0
  62. investing_algorithm_framework/cli/templates/data_providers.py.template +17 -0
  63. investing_algorithm_framework/cli/templates/env.example.template +2 -0
  64. investing_algorithm_framework/cli/templates/env_azure_function.example.template +4 -0
  65. investing_algorithm_framework/cli/templates/market_data_providers.py.template +9 -0
  66. investing_algorithm_framework/cli/templates/readme.md.template +135 -0
  67. investing_algorithm_framework/cli/templates/requirements.txt.template +2 -0
  68. investing_algorithm_framework/cli/templates/run_backtest.py.template +20 -0
  69. investing_algorithm_framework/cli/templates/strategy.py.template +124 -0
  70. investing_algorithm_framework/create_app.py +40 -6
  71. investing_algorithm_framework/dependency_container.py +72 -56
  72. investing_algorithm_framework/domain/__init__.py +71 -47
  73. investing_algorithm_framework/domain/backtesting/__init__.py +21 -0
  74. investing_algorithm_framework/domain/backtesting/backtest.py +503 -0
  75. investing_algorithm_framework/domain/backtesting/backtest_date_range.py +96 -0
  76. investing_algorithm_framework/domain/backtesting/backtest_evaluation_focuss.py +242 -0
  77. investing_algorithm_framework/domain/backtesting/backtest_metrics.py +459 -0
  78. investing_algorithm_framework/domain/backtesting/backtest_permutation_test.py +275 -0
  79. investing_algorithm_framework/domain/backtesting/backtest_run.py +605 -0
  80. investing_algorithm_framework/domain/backtesting/backtest_summary_metrics.py +162 -0
  81. investing_algorithm_framework/domain/backtesting/combine_backtests.py +280 -0
  82. investing_algorithm_framework/domain/config.py +59 -91
  83. investing_algorithm_framework/domain/constants.py +13 -38
  84. investing_algorithm_framework/domain/data_provider.py +334 -0
  85. investing_algorithm_framework/domain/data_structures.py +3 -2
  86. investing_algorithm_framework/domain/exceptions.py +51 -1
  87. investing_algorithm_framework/domain/models/__init__.py +17 -12
  88. investing_algorithm_framework/domain/models/data/__init__.py +7 -0
  89. investing_algorithm_framework/domain/models/data/data_source.py +214 -0
  90. investing_algorithm_framework/domain/models/data/data_type.py +46 -0
  91. investing_algorithm_framework/domain/models/event.py +35 -0
  92. investing_algorithm_framework/domain/models/market/market_credential.py +55 -1
  93. investing_algorithm_framework/domain/models/order/order.py +77 -83
  94. investing_algorithm_framework/domain/models/order/order_status.py +2 -2
  95. investing_algorithm_framework/domain/models/order/order_type.py +1 -3
  96. investing_algorithm_framework/domain/models/portfolio/portfolio.py +81 -3
  97. investing_algorithm_framework/domain/models/portfolio/portfolio_configuration.py +26 -3
  98. investing_algorithm_framework/domain/models/portfolio/portfolio_snapshot.py +108 -11
  99. investing_algorithm_framework/domain/models/position/__init__.py +2 -1
  100. investing_algorithm_framework/domain/models/position/position.py +12 -0
  101. investing_algorithm_framework/domain/models/position/position_size.py +41 -0
  102. investing_algorithm_framework/domain/models/risk_rules/__init__.py +7 -0
  103. investing_algorithm_framework/domain/models/risk_rules/stop_loss_rule.py +51 -0
  104. investing_algorithm_framework/domain/models/risk_rules/take_profit_rule.py +55 -0
  105. investing_algorithm_framework/domain/models/snapshot_interval.py +45 -0
  106. investing_algorithm_framework/domain/models/strategy_profile.py +19 -151
  107. investing_algorithm_framework/domain/models/time_frame.py +37 -0
  108. investing_algorithm_framework/domain/models/time_interval.py +33 -0
  109. investing_algorithm_framework/domain/models/time_unit.py +66 -2
  110. investing_algorithm_framework/domain/models/trade/__init__.py +8 -1
  111. investing_algorithm_framework/domain/models/trade/trade.py +295 -171
  112. investing_algorithm_framework/domain/models/trade/trade_status.py +9 -2
  113. investing_algorithm_framework/domain/models/trade/trade_stop_loss.py +332 -0
  114. investing_algorithm_framework/domain/models/trade/trade_take_profit.py +365 -0
  115. investing_algorithm_framework/domain/order_executor.py +112 -0
  116. investing_algorithm_framework/domain/portfolio_provider.py +118 -0
  117. investing_algorithm_framework/domain/services/__init__.py +2 -9
  118. investing_algorithm_framework/domain/services/portfolios/portfolio_sync_service.py +0 -6
  119. investing_algorithm_framework/domain/services/state_handler.py +38 -0
  120. investing_algorithm_framework/domain/strategy.py +1 -29
  121. investing_algorithm_framework/domain/utils/__init__.py +12 -7
  122. investing_algorithm_framework/domain/utils/custom_tqdm.py +22 -0
  123. investing_algorithm_framework/domain/utils/dates.py +57 -0
  124. investing_algorithm_framework/domain/utils/jupyter_notebook_detection.py +19 -0
  125. investing_algorithm_framework/domain/utils/polars.py +53 -0
  126. investing_algorithm_framework/domain/utils/random.py +29 -0
  127. investing_algorithm_framework/download_data.py +108 -0
  128. investing_algorithm_framework/infrastructure/__init__.py +31 -18
  129. investing_algorithm_framework/infrastructure/data_providers/__init__.py +36 -0
  130. investing_algorithm_framework/infrastructure/data_providers/ccxt.py +1143 -0
  131. investing_algorithm_framework/infrastructure/data_providers/csv.py +568 -0
  132. investing_algorithm_framework/infrastructure/data_providers/pandas.py +599 -0
  133. investing_algorithm_framework/infrastructure/database/__init__.py +6 -2
  134. investing_algorithm_framework/infrastructure/database/sql_alchemy.py +86 -12
  135. investing_algorithm_framework/infrastructure/models/__init__.py +6 -11
  136. investing_algorithm_framework/infrastructure/models/order/__init__.py +2 -1
  137. investing_algorithm_framework/infrastructure/models/order/order.py +35 -49
  138. investing_algorithm_framework/infrastructure/models/order/order_metadata.py +44 -0
  139. investing_algorithm_framework/infrastructure/models/order_trade_association.py +10 -0
  140. investing_algorithm_framework/infrastructure/models/portfolio/__init__.py +1 -1
  141. investing_algorithm_framework/infrastructure/models/portfolio/portfolio_snapshot.py +8 -0
  142. investing_algorithm_framework/infrastructure/models/portfolio/{portfolio.py → sql_portfolio.py} +17 -5
  143. investing_algorithm_framework/infrastructure/models/trades/__init__.py +9 -0
  144. investing_algorithm_framework/infrastructure/models/trades/trade.py +130 -0
  145. investing_algorithm_framework/infrastructure/models/trades/trade_stop_loss.py +59 -0
  146. investing_algorithm_framework/infrastructure/models/trades/trade_take_profit.py +55 -0
  147. investing_algorithm_framework/infrastructure/order_executors/__init__.py +21 -0
  148. investing_algorithm_framework/infrastructure/order_executors/backtest_oder_executor.py +28 -0
  149. investing_algorithm_framework/infrastructure/order_executors/ccxt_order_executor.py +200 -0
  150. investing_algorithm_framework/infrastructure/portfolio_providers/__init__.py +19 -0
  151. investing_algorithm_framework/infrastructure/portfolio_providers/ccxt_portfolio_provider.py +199 -0
  152. investing_algorithm_framework/infrastructure/repositories/__init__.py +8 -0
  153. investing_algorithm_framework/infrastructure/repositories/order_metadata_repository.py +17 -0
  154. investing_algorithm_framework/infrastructure/repositories/order_repository.py +5 -0
  155. investing_algorithm_framework/infrastructure/repositories/portfolio_repository.py +1 -1
  156. investing_algorithm_framework/infrastructure/repositories/position_repository.py +11 -0
  157. investing_algorithm_framework/infrastructure/repositories/repository.py +81 -27
  158. investing_algorithm_framework/infrastructure/repositories/trade_repository.py +71 -0
  159. investing_algorithm_framework/infrastructure/repositories/trade_stop_loss_repository.py +29 -0
  160. investing_algorithm_framework/infrastructure/repositories/trade_take_profit_repository.py +29 -0
  161. investing_algorithm_framework/infrastructure/services/__init__.py +4 -4
  162. investing_algorithm_framework/infrastructure/services/aws/__init__.py +6 -0
  163. investing_algorithm_framework/infrastructure/services/aws/state_handler.py +113 -0
  164. investing_algorithm_framework/infrastructure/services/azure/__init__.py +5 -0
  165. investing_algorithm_framework/infrastructure/services/azure/state_handler.py +158 -0
  166. investing_algorithm_framework/services/__init__.py +113 -16
  167. investing_algorithm_framework/services/backtesting/__init__.py +0 -7
  168. investing_algorithm_framework/services/backtesting/backtest_service.py +566 -359
  169. investing_algorithm_framework/services/configuration_service.py +77 -11
  170. investing_algorithm_framework/services/data_providers/__init__.py +5 -0
  171. investing_algorithm_framework/services/data_providers/data_provider_service.py +850 -0
  172. investing_algorithm_framework/services/market_credential_service.py +16 -1
  173. investing_algorithm_framework/services/metrics/__init__.py +114 -0
  174. investing_algorithm_framework/services/metrics/alpha.py +0 -0
  175. investing_algorithm_framework/services/metrics/beta.py +0 -0
  176. investing_algorithm_framework/services/metrics/cagr.py +60 -0
  177. investing_algorithm_framework/services/metrics/calmar_ratio.py +40 -0
  178. investing_algorithm_framework/services/metrics/drawdown.py +181 -0
  179. investing_algorithm_framework/services/metrics/equity_curve.py +24 -0
  180. investing_algorithm_framework/services/metrics/exposure.py +210 -0
  181. investing_algorithm_framework/services/metrics/generate.py +358 -0
  182. investing_algorithm_framework/services/metrics/mean_daily_return.py +83 -0
  183. investing_algorithm_framework/services/metrics/profit_factor.py +165 -0
  184. investing_algorithm_framework/services/metrics/recovery.py +113 -0
  185. investing_algorithm_framework/services/metrics/returns.py +452 -0
  186. investing_algorithm_framework/services/metrics/risk_free_rate.py +28 -0
  187. investing_algorithm_framework/services/metrics/sharpe_ratio.py +137 -0
  188. investing_algorithm_framework/services/metrics/sortino_ratio.py +74 -0
  189. investing_algorithm_framework/services/metrics/standard_deviation.py +157 -0
  190. investing_algorithm_framework/services/metrics/trades.py +500 -0
  191. investing_algorithm_framework/services/metrics/treynor_ratio.py +0 -0
  192. investing_algorithm_framework/services/metrics/ulcer.py +0 -0
  193. investing_algorithm_framework/services/metrics/value_at_risk.py +0 -0
  194. investing_algorithm_framework/services/metrics/volatility.py +97 -0
  195. investing_algorithm_framework/services/metrics/win_rate.py +177 -0
  196. investing_algorithm_framework/services/order_service/__init__.py +3 -1
  197. investing_algorithm_framework/services/order_service/order_backtest_service.py +76 -89
  198. investing_algorithm_framework/services/order_service/order_executor_lookup.py +110 -0
  199. investing_algorithm_framework/services/order_service/order_service.py +407 -326
  200. investing_algorithm_framework/services/portfolios/__init__.py +3 -1
  201. investing_algorithm_framework/services/portfolios/backtest_portfolio_service.py +37 -3
  202. investing_algorithm_framework/services/portfolios/portfolio_configuration_service.py +22 -8
  203. investing_algorithm_framework/services/portfolios/portfolio_provider_lookup.py +106 -0
  204. investing_algorithm_framework/services/portfolios/portfolio_service.py +96 -28
  205. investing_algorithm_framework/services/portfolios/portfolio_snapshot_service.py +97 -28
  206. investing_algorithm_framework/services/portfolios/portfolio_sync_service.py +116 -313
  207. investing_algorithm_framework/services/positions/__init__.py +7 -0
  208. investing_algorithm_framework/services/positions/position_service.py +210 -0
  209. investing_algorithm_framework/services/repository_service.py +8 -2
  210. investing_algorithm_framework/services/trade_order_evaluator/__init__.py +9 -0
  211. investing_algorithm_framework/services/trade_order_evaluator/backtest_trade_oder_evaluator.py +113 -0
  212. investing_algorithm_framework/services/trade_order_evaluator/default_trade_order_evaluator.py +51 -0
  213. investing_algorithm_framework/services/trade_order_evaluator/trade_order_evaluator.py +80 -0
  214. investing_algorithm_framework/services/trade_service/__init__.py +7 -1
  215. investing_algorithm_framework/services/trade_service/trade_service.py +1013 -315
  216. investing_algorithm_framework/services/trade_service/trade_stop_loss_service.py +39 -0
  217. investing_algorithm_framework/services/trade_service/trade_take_profit_service.py +41 -0
  218. investing_algorithm_framework-7.19.15.dist-info/METADATA +537 -0
  219. investing_algorithm_framework-7.19.15.dist-info/RECORD +263 -0
  220. investing_algorithm_framework-7.19.15.dist-info/entry_points.txt +3 -0
  221. investing_algorithm_framework/app/algorithm.py +0 -1105
  222. investing_algorithm_framework/domain/graphs.py +0 -382
  223. investing_algorithm_framework/domain/metrics/__init__.py +0 -6
  224. investing_algorithm_framework/domain/models/backtesting/__init__.py +0 -11
  225. investing_algorithm_framework/domain/models/backtesting/backtest_date_range.py +0 -43
  226. investing_algorithm_framework/domain/models/backtesting/backtest_position.py +0 -120
  227. investing_algorithm_framework/domain/models/backtesting/backtest_report.py +0 -580
  228. investing_algorithm_framework/domain/models/backtesting/backtest_reports_evaluation.py +0 -243
  229. investing_algorithm_framework/domain/models/trading_data_types.py +0 -47
  230. investing_algorithm_framework/domain/models/trading_time_frame.py +0 -223
  231. investing_algorithm_framework/domain/services/market_data_sources.py +0 -344
  232. investing_algorithm_framework/domain/services/market_service.py +0 -153
  233. investing_algorithm_framework/domain/singleton.py +0 -9
  234. investing_algorithm_framework/domain/utils/backtesting.py +0 -472
  235. investing_algorithm_framework/infrastructure/models/market_data_sources/__init__.py +0 -12
  236. investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py +0 -559
  237. investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py +0 -254
  238. investing_algorithm_framework/infrastructure/models/market_data_sources/us_treasury_yield.py +0 -47
  239. investing_algorithm_framework/infrastructure/services/market_service/__init__.py +0 -5
  240. investing_algorithm_framework/infrastructure/services/market_service/ccxt_market_service.py +0 -455
  241. investing_algorithm_framework/infrastructure/services/performance_service/__init__.py +0 -7
  242. investing_algorithm_framework/infrastructure/services/performance_service/backtest_performance_service.py +0 -2
  243. investing_algorithm_framework/infrastructure/services/performance_service/performance_service.py +0 -350
  244. investing_algorithm_framework/services/backtesting/backtest_report_writer_service.py +0 -53
  245. investing_algorithm_framework/services/backtesting/graphs.py +0 -61
  246. investing_algorithm_framework/services/market_data_source_service/__init__.py +0 -8
  247. investing_algorithm_framework/services/market_data_source_service/backtest_market_data_source_service.py +0 -150
  248. investing_algorithm_framework/services/market_data_source_service/market_data_source_service.py +0 -189
  249. investing_algorithm_framework/services/position_service.py +0 -31
  250. investing_algorithm_framework/services/strategy_orchestrator_service.py +0 -264
  251. investing_algorithm_framework-3.7.0.dist-info/METADATA +0 -339
  252. investing_algorithm_framework-3.7.0.dist-info/RECORD +0 -147
  253. /investing_algorithm_framework/{domain → services}/metrics/price_efficiency.py +0 -0
  254. /investing_algorithm_framework/services/{position_snapshot_service.py → positions/position_snapshot_service.py} +0 -0
  255. {investing_algorithm_framework-3.7.0.dist-info → investing_algorithm_framework-7.19.15.dist-info}/LICENSE +0 -0
  256. {investing_algorithm_framework-3.7.0.dist-info → investing_algorithm_framework-7.19.15.dist-info}/WHEEL +0 -0
@@ -1,5 +1,4 @@
1
1
  # Framework constants
2
- FRAMEWORK_NAME = 'FRAMEWORK_NAME'
3
2
  ENVIRONMENT = "ENVIRONMENT"
4
3
  STATELESS = "STATELESS"
5
4
 
@@ -8,70 +7,46 @@ DATABASE_CONFIG = 'DATABASE_CONFIG'
8
7
  DATABASE_NAME = 'DATABASE_NAME'
9
8
  DATABASE_TYPE = 'DATABASE_TYPE'
10
9
  DATABASE_DIRECTORY_PATH = 'DATABASE_DIRECTORY_PATH'
10
+ DATABASE_DIRECTORY_NAME = 'DATABASE_DIRECTORY_NAME'
11
11
  DATABASE_URL = 'DATABASE_URL'
12
12
  DEFAULT_DATABASE_NAME = "database"
13
13
 
14
- SYMBOLS = "SYMBOLS"
14
+ APPLICATION_DIRECTORY = "APP_DIR"
15
15
  RESOURCE_DIRECTORY = "RESOURCE_DIRECTORY"
16
16
  BACKTEST_DATA_DIRECTORY_NAME = "BACKTEST_DATA_DIRECTORY_NAME"
17
+ DATA_DIRECTORY = "DATA_DIRECTORY"
17
18
  LOG_LEVEL = 'LOG_LEVEL'
18
19
  BASE_DIR = 'BASE_DIR'
19
20
  SQLALCHEMY_DATABASE_URI = 'SQLALCHEMY_DATABASE_URI'
20
- SQLITE_INITIALIZED = "SQLITE_INITIALIZED"
21
21
  SQLALCHEMY_INITIALIZED = "SQLALCHEMY_INITIALIZED"
22
- RESERVED_BALANCES = "RESERVED_BALANCES"
23
22
  APP_MODE = "APP_MODE"
24
- BINANCE = "BINANCE"
25
23
 
26
- IDENTIFIER_QUERY_PARAM = "identifier"
27
- TARGET_SYMBOL_QUERY_PARAM = "target_symbol"
28
- TRADING_SYMBOL_QUERY_PARAM = "trading_symbol"
29
- ORDER_SIDE_QUERY_PARAM = "order_size"
30
- STATUS_QUERY_PARAM = "status"
31
- POSITION_SYMBOL_QUERY_PARAM = "position"
32
- SYMBOL_QUERY_PARAM = "symbol"
33
- TIME_FRAME_QUERY_PARAM = "time_frame"
34
-
35
- RESERVED_IDENTIFIERS = [
36
- BINANCE
37
- ]
38
-
39
- BINANCE_API_KEY = "binance_api_key"
40
- BINANCE_SECRET_KEY = "binance_secret_key"
41
24
 
42
25
  CHECK_PENDING_ORDERS = "CHECK_PENDING_ORDERS"
43
26
  RUN_STRATEGY = "RUN_STRATEGY"
44
27
 
45
28
  # Configuration
46
- TRADING_SYMBOL = "TRADING_SYMBOL"
47
- CCXT_ENABLED = "CCXT_ENABLED"
48
- API_KEY = "API_KEY"
49
- SECRET_KEY = "SECRET_KEY"
50
- MARKET = "MARKET"
51
- TRACK_PORTFOLIO_FROM = "TRACK_PORTFOLIO_FROM"
52
- SQLITE_ENABLED = "SQLITE_ENABLED"
53
- PORTFOLIOS = "PORTFOLIOS"
54
- STRATEGIES = "STRATEGIES"
55
- APPLICATION_CONFIGURED = "APPLICATION_CONFIGURED"
56
- ACTION = "ACTION"
57
-
58
29
  DEFAULT_PER_PAGE_VALUE = 10
59
30
  DEFAULT_PAGE_VALUE = 1
60
31
  ITEMIZE = 'itemize'
61
32
  ITEMIZED = 'itemized'
62
33
  PAGE = 'page'
63
34
  PER_PAGE = 'per_page'
64
-
65
- DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
66
- DATETIME_FORMAT_BACKTESTING = "%Y-%m-%d:%H:%M"
35
+ DATETIME_FORMAT_BACKTESTING = "%Y-%m-%d-%H-%M"
67
36
  CCXT_DATETIME_FORMAT_WITH_TIMEZONE = "%Y-%m-%dT%H:%M:%S.%fZ"
68
37
  CCXT_DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S.%f"
38
+ DEFAULT_DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
69
39
  BACKTESTING_FLAG = "BACKTESTING"
70
- BACKTESTING_INDEX_DATETIME = "BACKTESTING_INDEX_DATETIME"
40
+ INDEX_DATETIME = "INDEX_DATETIME"
41
+ LAST_SNAPSHOT_DATETIME = "LAST_SNAPSHOT_DATETIME"
71
42
  BACKTESTING_START_DATE = "BACKTESTING_START_DATE"
72
43
  BACKTESTING_END_DATE = "BACKTESTING_END_DATE"
73
- BACKTESTING_PENDING_ORDER_CHECK_INTERVAL \
74
- = "BACKTESTING_PENDING_ORDER_CHECK_INTERVAL"
44
+ BACKTESTING_INITIAL_AMOUNT = "BACKTESTING_INITIAL_AMOUNT"
75
45
  TICKER_DATA_TYPE = "TICKER"
76
46
  OHLCV_DATA_TYPE = "OHLCV"
77
47
  CURRENT_UTC_DATETIME = "CURRENT_UTC_DATETIME"
48
+ SNAPSHOT_INTERVAL = "SNAPSHOT_INTERVAL"
49
+ DATETIME_FORMAT = "DATETIME_FORMAT"
50
+ DATETIME_FORMAT_FILE_NAME = "DATETIME_FORMAT_FILE_NAME"
51
+ # Deployment
52
+ AWS_S3_STATE_BUCKET_NAME = "AWS_S3_STATE_BUCKET_NAME"
@@ -0,0 +1,334 @@
1
+ from typing import List, Any, Union
2
+ from abc import ABC, abstractmethod
3
+ from datetime import datetime
4
+ from investing_algorithm_framework.domain.exceptions import \
5
+ ImproperlyConfigured
6
+ from investing_algorithm_framework.domain.models.time_frame import TimeFrame
7
+ from investing_algorithm_framework.domain.models.data.data_type import DataType
8
+ from investing_algorithm_framework.domain.models.data.data_source import \
9
+ DataSource
10
+
11
+
12
+ class DataProvider(ABC):
13
+ """
14
+ Abstract base class for data providers. The DataProvider class
15
+ is responsible for fetching and preparing data for trading
16
+ algorithms.
17
+
18
+ Attributes:
19
+ data_type (DataType): The type of data to be
20
+ fetched (e.g., OHLCV, TICKER, CUSTOM_DATA).
21
+ symbol (Optional[List[str]]): A list supported symbols that the
22
+ data provider can provide data for. The framework will use this
23
+ list when searching for a data provider for a specific symbol.
24
+ Example: ["AAPL/USD", "GOOGL/USD", "MSFT/USD"]
25
+ priority (int): The priority of the data provider. The lower the
26
+ number, the higher the priority. The framework will use this
27
+ priority when searching for a data provider for a specific symbol.
28
+ Example: 0 is the highest priority, 1 is the second-highest
29
+ priority, etc. This is useful when multiple data providers
30
+ support the same symbol or market. The framework will use the
31
+ data provider with the highest priority.
32
+ time_frame (Optional[str]): The time frame for the data. This is
33
+ useful for data providers that support multiple time frames.
34
+ Example: "1m", "5m", "1h", "1d"
35
+ window_size (Optional[int]): The window size for the data. This is
36
+ useful for data providers that support multiple window sizes.
37
+ Example: 100, 200, 500
38
+ storage_path (Optional[str]): The path to the storage location
39
+ for the data. This is useful for data providers that support
40
+ saving data to a file
41
+ """
42
+ data_type: DataType = None
43
+ data_provider_identifier: str = None
44
+
45
+ def __init__(
46
+ self,
47
+ data_provider_identifier: str = None,
48
+ data_type: str = None,
49
+ symbol: str = None,
50
+ market: str = None,
51
+ priority: int = 0,
52
+ time_frame=None,
53
+ window_size=None,
54
+ storage_path=None,
55
+ storage_directory=None,
56
+ config=None,
57
+ ):
58
+ """
59
+ Initializes the DataProvider. The data provider should be defined
60
+ with a data_type and a data_provider_identifier. The data_type
61
+ should be a valid DataType, and the data_provider_identifier
62
+ should be a unique identifier for the data provider.
63
+
64
+ Args:
65
+ data_provider_identifier (str): The unique identifier for the
66
+ data provider. This is used to identify the data provider
67
+ in the framework. It should be a unique string that identifies
68
+ the data provider. Example: "binance",
69
+ "coinbase", "custom_feed_data"
70
+ data_type (str): The type of data to be fetched
71
+ (e.g., "OHLCV", "TICKER", "CUSTOM_DATA")
72
+ symbol (str): The symbol to fetch data for. This is optional and
73
+ can be set later. Example: "AAPL/USD", "BTC/USD"
74
+ market (str): The market to fetch data for.
75
+ This is optional and can be set later.
76
+ Example: "BINANCE", "COINBASE"
77
+ priority (int): The priority of the data provider. The lower the
78
+ number, the higher the priority. This is useful when multiple
79
+ data providers support the same symbol or market. The framework
80
+ will use the data provider with the highest priority.
81
+ Example: 0 is the highest priority, 1 is the second-highest
82
+ priority, etc.
83
+ time_frame (str): The time frame for the data. This is optional and
84
+ can be set later. This is useful for data providers
85
+ that support multiple time frames.
86
+ Example: "1m", "5m", "1h", "1d"
87
+ window_size (int): The window size for the data. This is optional
88
+ and can be set later. This is useful for data providers that
89
+ support multiple window sizes. Example: 100, 200, 500
90
+ storage_path (str): The path to the storage location for the data.
91
+ This is optional and can be set later. This is useful for data
92
+ providers that support saving data to a file.
93
+ Example: "/path/to/data"
94
+ """
95
+ self._data_type = None
96
+ self._time_frame = None
97
+
98
+ if data_type is not None:
99
+ self.data_type = DataType.from_value(data_type)
100
+
101
+ if time_frame is not None:
102
+ self.time_frame = TimeFrame.from_value(time_frame)
103
+
104
+ if data_provider_identifier is not None:
105
+ self.data_provider_identifier = data_provider_identifier
106
+
107
+ self.symbol = symbol
108
+
109
+ if self.symbol is not None:
110
+ self.symbol = self.symbol.upper()
111
+
112
+ self.market = market
113
+
114
+ if self.market is not None:
115
+ self.market = self.market.upper()
116
+
117
+ self.priority = priority
118
+ self._config = config
119
+ self.window_size = window_size
120
+ self.storage_path = storage_path
121
+ self.storage_directory = storage_directory
122
+ self._market_credentials = None
123
+
124
+ # Check if the data provider is properly configured
125
+ if self.data_type is None:
126
+ raise ImproperlyConfigured(
127
+ "DataProvider must be initialized "
128
+ "with a data_type. Either pass it as a parameter in "
129
+ "the constructor or set it as a class attribute."
130
+ )
131
+
132
+ if self.data_provider_identifier is None:
133
+ raise ImproperlyConfigured(
134
+ "DataProvider must be initialized with a "
135
+ "data_provider_identifier. Either pass it as a parameter "
136
+ "in the constructor or set it as a class attribute."
137
+ )
138
+
139
+ @property
140
+ def market_credentials(self):
141
+ """
142
+ Returns the market credentials for the data provider.
143
+ """
144
+ return self._market_credentials
145
+
146
+ @market_credentials.setter
147
+ def market_credentials(self, value: List):
148
+ """
149
+ Sets the market credentials for the data provider.
150
+ """
151
+ self._market_credentials = value
152
+
153
+ def get_credential(self, market: str):
154
+ """
155
+ Returns the credentials for the given market.
156
+ """
157
+ if self.market_credentials is None:
158
+ return None
159
+ for credential in self.market_credentials:
160
+ if credential.market == market:
161
+ return credential
162
+ return None
163
+
164
+ @property
165
+ def config(self):
166
+ return self._config
167
+
168
+ @config.setter
169
+ def config(self, value):
170
+ self._config = value
171
+
172
+ @abstractmethod
173
+ def has_data(
174
+ self,
175
+ data_source: DataSource,
176
+ start_date: datetime = None,
177
+ end_date: datetime = None,
178
+ ) -> bool:
179
+ """
180
+ Checks if the data provider has data for the given parameters.
181
+
182
+ Args:
183
+ data_source (DataSource): The data source specification that
184
+ matches a data provider.
185
+ start_date (datetime): The start date for the data.
186
+ end_date (datetime): The end date for the data.
187
+
188
+ Returns:
189
+ bool: True if the data provider has data for the given parameters,
190
+ """
191
+ raise NotImplementedError("Subclasses should implement this method.")
192
+
193
+ @abstractmethod
194
+ def get_data(
195
+ self,
196
+ date: datetime = None,
197
+ start_date: datetime = None,
198
+ end_date: datetime = None,
199
+ save: bool = False,
200
+ ) -> Any:
201
+ """
202
+ Fetches data for a given symbol and date range.
203
+
204
+ Args:
205
+ start_date (datetime): The start date for the data.
206
+ end_date (datetime): The end date for the data.
207
+ date (datetime): The specific date for which to fetch data.
208
+ save (bool): Whether to save the data to the storage path.
209
+
210
+ Returns:
211
+ Any: The data for the given symbol and date range.
212
+ This can be a DataFrame, a list, or any other data structure
213
+ depending on the implementation.
214
+ """
215
+ raise NotImplementedError("Subclasses should implement this method.")
216
+
217
+ @abstractmethod
218
+ def prepare_backtest_data(
219
+ self,
220
+ backtest_start_date,
221
+ backtest_end_date,
222
+ ) -> None:
223
+ """
224
+ Prepares backtest data for a given symbol and date range.
225
+
226
+ Args:
227
+ backtest_start_date (datetime): The start date for the
228
+ backtest data.
229
+ backtest_end_date (datetime): The end date for the
230
+ backtest data.
231
+
232
+ Returns:
233
+ None
234
+ """
235
+ raise NotImplementedError("Subclasses should implement this method.")
236
+
237
+ @abstractmethod
238
+ def get_backtest_data(
239
+ self,
240
+ backtest_index_date: datetime,
241
+ backtest_start_date: datetime = None,
242
+ backtest_end_date: datetime = None,
243
+ data_source: DataSource = None,
244
+ ) -> Any:
245
+ """
246
+ Fetches backtest data for a given datasource
247
+
248
+ Args:
249
+ backtest_index_date (datetime): The date for which to fetch
250
+ backtest data.
251
+ backtest_start_date (datetime): The start date for the
252
+ backtest data.
253
+ backtest_end_date (datetime): The end date for the
254
+ backtest data.
255
+ data_source (Optional[DataSource]): The data source
256
+ specification that is used to fetch the data.
257
+ This param is optional and can be used to
258
+ help identify errors in data fetching.
259
+
260
+ Returns:
261
+ Any: The data for the given symbol and date range.
262
+ This can be a DataFrame, a list, or any other data structure
263
+ depending on the implementation.
264
+ """
265
+ raise NotImplementedError("Subclasses should implement this method.")
266
+
267
+ @abstractmethod
268
+ def copy(self, data_source: DataSource) -> "DataProvider":
269
+ """
270
+ Returns a copy of the data provider instance based on a
271
+ given data source. The data source is previously matched
272
+ with the 'has_data' method. Then a new instance of the data
273
+ provider must be registered in the framework so that each
274
+ data source has its own instance of the data provider.
275
+
276
+ Args:
277
+ data_source (DataSource): The data source specification that
278
+ matches a data provider.
279
+
280
+ Returns:
281
+ DataProvider: A new instance of the data provider with the same
282
+ configuration.
283
+ """
284
+ raise NotImplementedError("Subclasses should implement this method.")
285
+
286
+ @abstractmethod
287
+ def get_number_of_data_points(
288
+ self,
289
+ start_date: datetime,
290
+ end_date: datetime,
291
+ ) -> int:
292
+ """
293
+ Returns the number of data points available between the
294
+ given start and end dates.
295
+
296
+ Args:
297
+ start_date (datetime): The start date for the data points.
298
+ end_date (datetime): The end date for the data points.
299
+ Returns:
300
+ int: The number of data points available between the
301
+ given start and end dates.
302
+ """
303
+ raise NotImplementedError("Subclasses should implement this method.")
304
+
305
+ @abstractmethod
306
+ def get_missing_data_dates(
307
+ self,
308
+ start_date: datetime,
309
+ end_date: datetime,
310
+ ) -> List[datetime]:
311
+ """
312
+ Returns a list of dates for which data is missing between the
313
+ given start and end dates.
314
+
315
+ Args:
316
+ start_date (datetime): The start date for checking missing data.
317
+ end_date (datetime): The end date for checking missing data.
318
+
319
+ Returns:
320
+ List[datetime]: A list of dates for which data is missing
321
+ between the given start and end dates.
322
+ """
323
+ raise NotImplementedError("Subclasses should implement this method.")
324
+
325
+ @abstractmethod
326
+ def get_data_source_file_path(self) -> Union[str, None]:
327
+ """
328
+ Returns the file path for the given data source if applicable.
329
+
330
+ Returns:
331
+ Union[str, None]: The file path for the data source or None
332
+ if not applicable.
333
+ """
334
+ raise NotImplementedError("Subclasses should implement this method.")
@@ -1,6 +1,6 @@
1
1
  class PeekableQueue:
2
- def __init__(self):
3
- self.queue = []
2
+ def __init__(self, items=[]):
3
+ self.queue = items
4
4
  self.index = 0
5
5
 
6
6
  def enqueue(self, item):
@@ -24,6 +24,7 @@ class PeekableQueue:
24
24
  def __len__(self):
25
25
  return len(self.queue)
26
26
 
27
+ @property
27
28
  def size(self):
28
29
  return len(self.queue)
29
30
 
@@ -49,7 +49,14 @@ class ImproperlyConfigured(Exception):
49
49
  class OperationalException(Exception):
50
50
  """
51
51
  Class OperationalException: Exception class indicating a problem occurred
52
- during running of the investing_algorithm_framework
52
+ during running of the investing_algorithm_framework.
53
+
54
+ This exception is used to indicate that an error occurred during the
55
+ operation of the investing_algorithm_framework, such as during a backtest,
56
+ strategy execution, or any other operational aspect of the framework.
57
+
58
+ Attributes:
59
+ message (str): The error message to be returned in the response.
53
60
  """
54
61
  def __init__(self, message) -> None:
55
62
  super(OperationalException, self).__init__(message)
@@ -60,3 +67,46 @@ class OperationalException(Exception):
60
67
  "status": "error",
61
68
  "message": self.error_message
62
69
  }
70
+
71
+
72
+ class NetworkError(Exception):
73
+ """
74
+ Class NetworkError: Exception class indicating a problem occurred
75
+ during making a netwok request
76
+ """
77
+
78
+ def __init__(self, message) -> None:
79
+ super(NetworkError, self).__init__(message)
80
+ self.error_message = message
81
+
82
+ def to_response(self):
83
+ return {
84
+ "status": "error",
85
+ "message": self.error_message
86
+ }
87
+
88
+
89
+ class DataError(Exception):
90
+ """
91
+ Class DataError: Exception class indicating a problem occurred
92
+ during data retrieval or processing
93
+ """
94
+
95
+ def __init__(
96
+ self,
97
+ message,
98
+ data_source_file_path: str = None,
99
+ number_of_missing_data_points: int = None,
100
+ total_number_of_data_points: int = None,
101
+ ) -> None:
102
+ super(DataError, self).__init__(message)
103
+ self.error_message = message
104
+ self.data_source_file_path = data_source_file_path
105
+ self.number_of_missing_data_points = number_of_missing_data_points
106
+ self.total_number_of_data_points = total_number_of_data_points
107
+
108
+ def to_response(self):
109
+ return {
110
+ "status": "error",
111
+ "message": self.error_message
112
+ }
@@ -1,17 +1,17 @@
1
1
  from .app_mode import AppMode
2
- from .backtesting import BacktestReport, BacktestPosition, \
3
- BacktestReportsEvaluation, BacktestDateRange
4
2
  from .market import MarketCredential
5
3
  from .order import OrderStatus, OrderSide, OrderType, Order
6
4
  from .portfolio import PortfolioConfiguration, Portfolio, PortfolioSnapshot
7
- from .position import Position, PositionSnapshot
5
+ from .position import Position, PositionSnapshot, PositionSize
8
6
  from .strategy_profile import StrategyProfile
9
7
  from .time_frame import TimeFrame
10
8
  from .time_interval import TimeInterval
11
9
  from .time_unit import TimeUnit
12
- from .trade import Trade, TradeStatus
13
- from .trading_data_types import TradingDataType
14
- from .trading_time_frame import TradingTimeFrame
10
+ from .trade import Trade, TradeStatus, TradeStopLoss, TradeTakeProfit
11
+ from .snapshot_interval import SnapshotInterval
12
+ from .event import Event
13
+ from .data import DataSource, DataType
14
+ from .risk_rules import TakeProfitRule, StopLossRule
15
15
 
16
16
  __all__ = [
17
17
  "OrderStatus",
@@ -21,20 +21,25 @@ __all__ = [
21
21
  "TimeFrame",
22
22
  "TimeInterval",
23
23
  "TimeUnit",
24
- "TradingTimeFrame",
25
- "TradingDataType",
26
24
  "PortfolioConfiguration",
27
25
  "Position",
28
26
  "Portfolio",
29
- "BacktestReport",
30
27
  "PositionSnapshot",
31
28
  "PortfolioSnapshot",
32
29
  "StrategyProfile",
33
- "BacktestPosition",
34
30
  "Trade",
35
31
  "MarketCredential",
36
32
  "TradeStatus",
37
- "BacktestReportsEvaluation",
33
+ "DataType",
38
34
  "AppMode",
39
- "BacktestDateRange"
35
+ "DataSource",
36
+ "AppMode",
37
+ "TradeStopLoss",
38
+ "TradeTakeProfit",
39
+ "DataSource",
40
+ "SnapshotInterval",
41
+ "Event",
42
+ "PositionSize",
43
+ "StopLossRule",
44
+ "TakeProfitRule",
40
45
  ]
@@ -0,0 +1,7 @@
1
+ from .data_source import DataSource
2
+ from .data_type import DataType
3
+
4
+ __all__ = [
5
+ "DataSource",
6
+ "DataType",
7
+ ]