investing-algorithm-framework 1.7.8__tar.gz → 1.7.10__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 (135) hide show
  1. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/PKG-INFO +51 -31
  2. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/README.md +50 -30
  3. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/algorithm.py +75 -16
  4. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/__init__.py +4 -2
  5. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/constants.py +1 -0
  6. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/order_backtest_service.py +1 -1
  7. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/order_service.py +4 -7
  8. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework.egg-info/PKG-INFO +51 -31
  9. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/AUTHORS.md +0 -0
  10. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/LICENSE +0 -0
  11. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/__init__.py +0 -0
  12. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/__init__.py +0 -0
  13. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/app.py +0 -0
  14. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/stateless/__init__.py +0 -0
  15. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/stateless/action_handlers/__init__.py +0 -0
  16. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/stateless/action_handlers/action_handler_strategy.py +0 -0
  17. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/stateless/action_handlers/check_online_handler.py +0 -0
  18. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/stateless/action_handlers/run_strategy_handler.py +0 -0
  19. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/stateless/exception_handler.py +0 -0
  20. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/strategy.py +0 -0
  21. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/task.py +0 -0
  22. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/__init__.py +0 -0
  23. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/controllers/__init__.py +0 -0
  24. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/controllers/orders.py +0 -0
  25. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/controllers/portfolio.py +0 -0
  26. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/controllers/positions.py +0 -0
  27. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/create_app.py +0 -0
  28. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/error_handler.py +0 -0
  29. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/responses.py +0 -0
  30. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/run_strategies.py +0 -0
  31. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/schemas/__init__.py +0 -0
  32. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/schemas/order.py +0 -0
  33. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/schemas/portfolio.py +0 -0
  34. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/schemas/position.py +0 -0
  35. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/setup_cors.py +0 -0
  36. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/create_app.py +0 -0
  37. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/dependency_container.py +0 -0
  38. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/config.py +0 -0
  39. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/decimal_parsing.py +0 -0
  40. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/exceptions.py +0 -0
  41. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/__init__.py +0 -0
  42. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/backtest_profile.py +0 -0
  43. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/base_model.py +0 -0
  44. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/market_data/__init__.py +0 -0
  45. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/market_data/asset_price.py +0 -0
  46. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/market_data/ohlcv.py +0 -0
  47. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/market_data/order_book.py +0 -0
  48. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/market_data/ticker.py +0 -0
  49. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/__init__.py +0 -0
  50. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/order.py +0 -0
  51. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/order_fee.py +0 -0
  52. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/order_side.py +0 -0
  53. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/order_status.py +0 -0
  54. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/order_type.py +0 -0
  55. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/portfolio/__init__.py +0 -0
  56. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/portfolio/backtest_portfolio_configuration.py +0 -0
  57. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/portfolio/portfolio.py +0 -0
  58. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/portfolio/portfolio_configuration.py +0 -0
  59. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/portfolio/portfolio_snapshot.py +0 -0
  60. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/position/__init__.py +0 -0
  61. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/position/position.py +0 -0
  62. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/position/position_snapshot.py +0 -0
  63. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/strategy_profile.py +0 -0
  64. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/time_frame.py +0 -0
  65. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/time_interval.py +0 -0
  66. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/time_unit.py +0 -0
  67. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/trade.py +1 -1
  68. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/trading_data_types.py +0 -0
  69. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/trading_time_frame.py +0 -0
  70. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/services/__init__.py +0 -0
  71. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/services/market_data_sources.py +0 -0
  72. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/services/order_executor_service.py +0 -0
  73. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/singleton.py +0 -0
  74. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/stateless_actions.py +0 -0
  75. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/strategy.py +0 -0
  76. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/__init__.py +0 -0
  77. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/backtesting.py +0 -0
  78. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/csv.py +0 -0
  79. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/random.py +0 -0
  80. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/signatures.py +0 -0
  81. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/stoppable_thread.py +0 -0
  82. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/synchronized.py +0 -0
  83. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/__init__.py +0 -0
  84. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/database/__init__.py +0 -0
  85. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/database/sql_alchemy.py +0 -0
  86. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/__init__.py +0 -0
  87. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/decimal_parser.py +0 -0
  88. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/market_data_sources/__init__.py +0 -0
  89. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py +0 -0
  90. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py +0 -0
  91. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/model_extension.py +0 -0
  92. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/order/__init__.py +0 -0
  93. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/order/order.py +0 -0
  94. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/order/order_fee.py +0 -0
  95. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/portfolio/__init__.py +0 -0
  96. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/portfolio/portfolio.py +0 -0
  97. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/portfolio/portfolio_snapshot.py +0 -0
  98. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/position/__init__.py +0 -0
  99. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/position/position.py +0 -0
  100. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/position/position_snapshot.py +0 -0
  101. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/__init__.py +0 -0
  102. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/order_fee_repository.py +0 -0
  103. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/order_repository.py +0 -0
  104. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/portfolio_repository.py +0 -0
  105. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/portfolio_snapshot_repository.py +0 -0
  106. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/position_repository.py +0 -0
  107. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/position_snapshot_repository.py +0 -0
  108. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/repository.py +0 -0
  109. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/__init__.py +0 -0
  110. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/market_service/__init__.py +0 -0
  111. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/market_service/backtest_market_service.py +0 -0
  112. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/market_service/ccxt_market_service.py +0 -0
  113. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/market_service/market_service.py +0 -0
  114. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/performance_service/__init__.py +0 -0
  115. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/performance_service/backtest_performance_service.py +0 -0
  116. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/performance_service/performance_service.py +0 -0
  117. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/__init__.py +0 -0
  118. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/backtest_service.py +0 -0
  119. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/configuration_service.py +0 -0
  120. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/market_data_service.py +0 -0
  121. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/portfolio_configuration_service.py +0 -0
  122. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/portfolio_service.py +0 -0
  123. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/portfolio_snapshot_service.py +0 -0
  124. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/position_cost_service.py +0 -0
  125. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/position_service.py +0 -0
  126. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/position_snapshot_service.py +0 -0
  127. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/repository_service.py +0 -0
  128. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/strategy_orchestrator_service.py +0 -0
  129. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework.egg-info/SOURCES.txt +0 -0
  130. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework.egg-info/dependency_links.txt +0 -0
  131. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework.egg-info/requires.txt +0 -0
  132. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework.egg-info/top_level.txt +0 -0
  133. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/setup.cfg +0 -0
  134. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/setup.py +0 -0
  135. {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/tests/test_create_app.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: investing_algorithm_framework
3
- Version: 1.7.8
3
+ Version: 1.7.10
4
4
  Summary: A framework for creating an investment algorithm
5
5
  Home-page: https://github.com/coding-kitties/investing-algorithm-framework.git
6
6
  Download-URL: https://github.com/coding-kitties/investing-algorithm-framework/archive/v0.1.1.tar.gz
@@ -169,63 +169,83 @@ if __name__ == "__main__":
169
169
  For more examples, check out the [examples](./examples/backtesting) folder.
170
170
 
171
171
  ### Backtesting report
172
- You can use the ```pretty_print_backtest``` function to print a backtesting report.
172
+ You can use the ```pretty_print_backtest``` function to print a backtest report.
173
173
  For example if you run the [moving average example trading bot](./examples/backtesting/moving_average.py)
174
174
  you will get the following backtesting report:
175
175
 
176
176
  ```bash
177
177
  ====================Backtest report===============================
178
- * Start date: 2021-04-03 00:00:00
179
- * End date: 2021-06-26 00:00:00
180
- * Number of days: 84
181
- * Number of runs: 1009
178
+ * Start date: 2023-08-24 00:00:00
179
+ * End date: 2023-12-02 00:00:00
180
+ * Number of days: 100
181
+ * Number of runs: 1201
182
182
  ====================Portfolio overview============================
183
- * Number of orders: 24
183
+ * Number of orders: 41
184
184
  * Initial balance: 400.0000 EUR
185
- * Final balance: 380.7132 EUR
186
- * Total net gain: -19.2868 EUR
187
- * Total net gain percentage: -4.8217%
188
- * Growth rate: -4.8217%
189
- * Growth -19.2868 EUR
185
+ * Final balance: 440.9081 EUR
186
+ * Total net gain: 40.4219 EUR
187
+ * Total net gain percentage: 10.1055%
188
+ * Growth rate: 10.2270%
189
+ * Growth 40.9081 EUR
190
190
  ====================Positions overview========================
191
191
  ╭────────────┬──────────┬──────────────────┬──────────────┬───────────────┬───────────────────────────┬────────────────┬───────────────╮
192
192
  │ Position │ Amount │ Pending amount │ Cost (EUR) │ Value (EUR) │ Percentage of portfolio │ Growth (EUR) │ Growth_rate │
193
193
  ├────────────┼──────────┼──────────────────┼──────────────┼───────────────┼───────────────────────────┼────────────────┼───────────────┤
194
- │ EUR │ 380.713 │ 0 │ 380.713 │ 380.713 │ 100.0000% │ 0 │ 0.0000% │
194
+ │ EUR │ 330.317 │ 0 │ 330.317 │ 330.317 │ 74.9174% │ 0 │ 0.0000% │
195
+ ├────────────┼──────────┼──────────────────┼──────────────┼───────────────┼───────────────────────────┼────────────────┼───────────────┤
196
+ │ DOT │ 22.0034 │ 0 │ 110.105 │ 110.591 │ 25.0826% │ 0.4863 │ 0.4416% │
195
197
  ╰────────────┴──────────┴──────────────────┴──────────────┴───────────────┴───────────────────────────┴────────────────┴───────────────╯
196
198
  ====================Trades overview===========================
197
- * Number of trades closed: 12
198
- * Number of trades open: 0
199
- * Percentage of positive trades: 25.0%
200
- * Percentage of negative trades: 75.0%
201
- * Average trade size: 96.9068 EUR
202
- * Average trade duration: 69.16666666666667 hours
199
+ * Number of trades closed: 20
200
+ * Number of trades open: 1
201
+ * Percentage of positive trades: 39.02439024390244%
202
+ * Percentage of negative trades: 58.536585365853654%
203
+ * Average trade size: 101.5585 EUR
204
+ * Average trade duration: 92.5 hours
203
205
  ╭─────────┬─────────────────────┬─────────────────────┬────────────────────┬──────────────┬──────────────────┬───────────────────────┬────────────────────┬─────────────────────╮
204
206
  │ Pair │ Open date │ Close date │ Duration (hours) │ Size (EUR) │ Net gain (EUR) │ Net gain percentage │ Open price (EUR) │ Close price (EUR) │
205
207
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
206
- │ BTC-EUR │ 2021-06-24 14:00:00 │ 2021-06-25 22:00:00 │ 32 │ 93.786 │ -5.0787 │ -5.4152% │ 28420 │ 26881 │
208
+ │ DOT-EUR │ 2023-11-30 16:00:00 │ │ 259.148 │ 110.105 │ 0 │ 0.0000% │ 5.004 │ │
209
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
210
+ │ DOT-EUR │ 2023-11-24 12:00:00 │ 2023-11-27 14:00:00 │ 74 │ 110.725 │ -2.4793 │ -2.2392% │ 4.7964 │ 4.689 │
211
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
212
+ │ DOT-EUR │ 2023-11-20 00:00:00 │ 2023-11-21 08:00:00 │ 32 │ 111.695 │ -3.8798 │ -3.4735% │ 4.9805 │ 4.8075 │
213
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
214
+ │ BTC-EUR │ 2023-11-16 20:00:00 │ 2023-11-20 00:00:00 │ 76 │ 109.263 │ 2.5245 │ 2.3105% │ 33110 │ 33875 │
215
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
216
+ │ BTC-EUR │ 2023-11-06 10:00:00 │ 2023-11-13 14:00:00 │ 172 │ 107.996 │ 5.7387 │ 5.3138% │ 32726 │ 34465 │
217
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
218
+ │ DOT-EUR │ 2023-10-20 12:00:00 │ 2023-10-27 08:00:00 │ 164 │ 100.652 │ 11.2336 │ 11.1608% │ 3.5526 │ 3.9491 │
219
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
220
+ │ BTC-EUR │ 2023-10-14 04:00:00 │ 2023-10-27 22:00:00 │ 330 │ 99.957 │ 24.6753 │ 24.6859% │ 25630 │ 31957 │
221
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
222
+ │ DOT-EUR │ 2023-10-14 04:00:00 │ 2023-10-17 14:00:00 │ 82 │ 100.946 │ -1.1753 │ -1.1643% │ 3.5643 │ 3.5228 │
223
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
224
+ │ DOT-EUR │ 2023-10-07 08:00:00 │ 2023-10-08 06:00:00 │ 22 │ 101.211 │ -1.0607 │ -1.0480% │ 3.874 │ 3.8334 │
225
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
226
+ │ BTC-EUR │ 2023-09-27 10:00:00 │ 2023-10-05 20:00:00 │ 202 │ 97.4688 │ 4.0365 │ 4.1413% │ 24992 │ 26027 │
207
227
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
208
- │ BTC-EUR │ 2021-06-23 16:00:00 │ 2021-06-23 20:00:00 │ 4 │ 95.9956 │ -1.3022 │ -1.3565% │ 28234 │ 27851 │
228
+ │ DOT-EUR │ 2023-09-27 10:00:00 │ 2023-10-03 22:00:00 │ 156 │ 99.7074 │ 1.9774 │ 1.9832% │ 3.8271 │ 3.903 │
209
229
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
210
- │ BTC-EUR │ 2021-06-13 20:00:00 │ 2021-06-17 06:00:00 │ 82 │ 96.501 │ 1.014 │ 1.0508% │ 32167 │ 32505 │
230
+ │ DOT-EUR │ 2023-09-25 12:00:00 │ 2023-09-27 04:00:00 │ 40 │ 99.7994 │ -0.3672 │ -0.3679% │ 3.8052 │ 3.7912 │
211
231
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
212
- │ BTC-EUR │ 2021-06-09 20:00:00 │ 2021-06-12 18:00:00 │ 70 │ 95.3472 │ -1.424 │ -1.4935% │ 29796 │ 29351 │
232
+ │ DOT-EUR │ 2023-09-14 18:00:00 │ 2023-09-18 02:00:00 │ 80 │ 99.4298 │ -0.1612 │ -0.1621% │ 3.8244 │ 3.8182 │
213
233
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
214
- │ BTC-EUR │ 2021-05-31 20:00:00 │ 2021-06-04 18:00:00 │ 94 │ 96.4384 │ 1.0432 │ 1.0817% │ 30137 │ 30463 │
234
+ │ BTC-EUR │ 2023-09-12 16:00:00 │ 2023-09-21 18:00:00 │ 218 │ 98.008 │ 1.64 │ 1.6733% │ 24502 │ 24912 │
215
235
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
216
- │ BTC-EUR │ 2021-05-24 20:00:00 │ 2021-05-28 10:00:00 │ 86 │ 97.476 │ -6.732 │ -6.9063% │ 32492 │ 30248 │
236
+ │ BTC-EUR │ 2023-09-07 02:00:00 │ 2023-09-10 16:00:00 │ 86 │ 98.4656 │ 0.4592 │ 0.4664% │ 24016 │ 24128 │
217
237
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
218
- │ BTC-EUR │ 2021-05-07 16:00:00 │ 2021-05-10 22:00:00 │ 78 │ 95.296 │ -4.578 │ -4.8040% │ 47648 │ 45359 │
238
+ │ DOT-EUR │ 2023-09-07 00:00:00 │ 2023-09-09 02:00:00 │ 50 │ 99.3915 │ -0.307 │ -0.3089% │ 3.982 │ 3.9697 │
219
239
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
220
- │ BTC-EUR │ 2021-05-05 22:00:00 │ 2021-05-07 06:00:00 │ 32 │ 99.4392 │ -2.4423 │ -2.4561% │ 47352 │ 46189 │
240
+ │ BTC-EUR │ 2023-09-06 00:00:00 │ 2023-09-06 12:00:00 │ 12 │ 98.5558 │ -0.3116 │ -0.3162% │ 24038 │ 23962 │
221
241
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
222
- │ BTC-EUR │ 2021-04-30 14:00:00 │ 2021-05-04 06:00:00 │ 88 │ 97.4694 │ -0.1974 │ -0.2025% │ 46414 │ 46320 │
242
+ │ DOT-EUR │ 2023-09-05 12:00:00 │ 2023-09-06 16:00:00 │ 28 │ 99.6655 │ -0.7846 │ -0.7872% │ 3.9759 │ 3.9446 │
223
243
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
224
- │ BTC-EUR │ 2021-04-26 10:00:00 │ 2021-04-29 20:00:00 │ 82 │ 97.3544 │ -1.6874 │ -1.7333% │ 44252 │ 43485 │
244
+ │ BTC-EUR │ 2023-09-04 18:00:00 │ 2023-09-04 22:00:00 │ 4 │ 98.2565 │ -0.0164 │ -0.0167% │ 23965 │ 23961 │
225
245
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
226
- │ BTC-EUR │ 2021-04-09 10:00:00 │ 2021-04-16 12:00:00 │ 170 │ 98.1 │ 3.82 │ 3.8940% │ 49050 │ 50960 │
246
+ │ DOT-EUR │ 2023-09-04 08:00:00 │ 2023-09-04 22:00:00 │ 14 │ 99.9766 │ -1.2274 │ -1.2277% │ 3.9748 │ 3.926 │
227
247
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
228
- │ BTC-EUR │ 2021-04-06 04:00:00 │ 2021-04-06 16:00:00 │ 12 │ 99.678 │ -1.722 │ -1.7276% │ 49839 │ 48978 │
248
+ │ DOT-EUR │ 2023-08-25 02:00:00 │ 2023-08-25 10:00:00 │ 8 │ 99.9996 │ -0.0928 │ -0.0928% │ 4.0968 │ 4.093 │
229
249
  ╰─────────┴─────────────────────┴─────────────────────┴────────────────────┴──────────────┴──────────────────┴───────────────────────┴────────────────────┴─────────────────────╯
230
250
  ==================================================================
231
251
  ```
@@ -132,63 +132,83 @@ if __name__ == "__main__":
132
132
  For more examples, check out the [examples](./examples/backtesting) folder.
133
133
 
134
134
  ### Backtesting report
135
- You can use the ```pretty_print_backtest``` function to print a backtesting report.
135
+ You can use the ```pretty_print_backtest``` function to print a backtest report.
136
136
  For example if you run the [moving average example trading bot](./examples/backtesting/moving_average.py)
137
137
  you will get the following backtesting report:
138
138
 
139
139
  ```bash
140
140
  ====================Backtest report===============================
141
- * Start date: 2021-04-03 00:00:00
142
- * End date: 2021-06-26 00:00:00
143
- * Number of days: 84
144
- * Number of runs: 1009
141
+ * Start date: 2023-08-24 00:00:00
142
+ * End date: 2023-12-02 00:00:00
143
+ * Number of days: 100
144
+ * Number of runs: 1201
145
145
  ====================Portfolio overview============================
146
- * Number of orders: 24
146
+ * Number of orders: 41
147
147
  * Initial balance: 400.0000 EUR
148
- * Final balance: 380.7132 EUR
149
- * Total net gain: -19.2868 EUR
150
- * Total net gain percentage: -4.8217%
151
- * Growth rate: -4.8217%
152
- * Growth -19.2868 EUR
148
+ * Final balance: 440.9081 EUR
149
+ * Total net gain: 40.4219 EUR
150
+ * Total net gain percentage: 10.1055%
151
+ * Growth rate: 10.2270%
152
+ * Growth 40.9081 EUR
153
153
  ====================Positions overview========================
154
154
  ╭────────────┬──────────┬──────────────────┬──────────────┬───────────────┬───────────────────────────┬────────────────┬───────────────╮
155
155
  │ Position │ Amount │ Pending amount │ Cost (EUR) │ Value (EUR) │ Percentage of portfolio │ Growth (EUR) │ Growth_rate │
156
156
  ├────────────┼──────────┼──────────────────┼──────────────┼───────────────┼───────────────────────────┼────────────────┼───────────────┤
157
- │ EUR │ 380.713 │ 0 │ 380.713 │ 380.713 │ 100.0000% │ 0 │ 0.0000% │
157
+ │ EUR │ 330.317 │ 0 │ 330.317 │ 330.317 │ 74.9174% │ 0 │ 0.0000% │
158
+ ├────────────┼──────────┼──────────────────┼──────────────┼───────────────┼───────────────────────────┼────────────────┼───────────────┤
159
+ │ DOT │ 22.0034 │ 0 │ 110.105 │ 110.591 │ 25.0826% │ 0.4863 │ 0.4416% │
158
160
  ╰────────────┴──────────┴──────────────────┴──────────────┴───────────────┴───────────────────────────┴────────────────┴───────────────╯
159
161
  ====================Trades overview===========================
160
- * Number of trades closed: 12
161
- * Number of trades open: 0
162
- * Percentage of positive trades: 25.0%
163
- * Percentage of negative trades: 75.0%
164
- * Average trade size: 96.9068 EUR
165
- * Average trade duration: 69.16666666666667 hours
162
+ * Number of trades closed: 20
163
+ * Number of trades open: 1
164
+ * Percentage of positive trades: 39.02439024390244%
165
+ * Percentage of negative trades: 58.536585365853654%
166
+ * Average trade size: 101.5585 EUR
167
+ * Average trade duration: 92.5 hours
166
168
  ╭─────────┬─────────────────────┬─────────────────────┬────────────────────┬──────────────┬──────────────────┬───────────────────────┬────────────────────┬─────────────────────╮
167
169
  │ Pair │ Open date │ Close date │ Duration (hours) │ Size (EUR) │ Net gain (EUR) │ Net gain percentage │ Open price (EUR) │ Close price (EUR) │
168
170
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
169
- │ BTC-EUR │ 2021-06-24 14:00:00 │ 2021-06-25 22:00:00 │ 32 │ 93.786 │ -5.0787 │ -5.4152% │ 28420 │ 26881 │
171
+ │ DOT-EUR │ 2023-11-30 16:00:00 │ │ 259.148 │ 110.105 │ 0 │ 0.0000% │ 5.004 │ │
172
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
173
+ │ DOT-EUR │ 2023-11-24 12:00:00 │ 2023-11-27 14:00:00 │ 74 │ 110.725 │ -2.4793 │ -2.2392% │ 4.7964 │ 4.689 │
174
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
175
+ │ DOT-EUR │ 2023-11-20 00:00:00 │ 2023-11-21 08:00:00 │ 32 │ 111.695 │ -3.8798 │ -3.4735% │ 4.9805 │ 4.8075 │
176
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
177
+ │ BTC-EUR │ 2023-11-16 20:00:00 │ 2023-11-20 00:00:00 │ 76 │ 109.263 │ 2.5245 │ 2.3105% │ 33110 │ 33875 │
178
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
179
+ │ BTC-EUR │ 2023-11-06 10:00:00 │ 2023-11-13 14:00:00 │ 172 │ 107.996 │ 5.7387 │ 5.3138% │ 32726 │ 34465 │
180
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
181
+ │ DOT-EUR │ 2023-10-20 12:00:00 │ 2023-10-27 08:00:00 │ 164 │ 100.652 │ 11.2336 │ 11.1608% │ 3.5526 │ 3.9491 │
182
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
183
+ │ BTC-EUR │ 2023-10-14 04:00:00 │ 2023-10-27 22:00:00 │ 330 │ 99.957 │ 24.6753 │ 24.6859% │ 25630 │ 31957 │
184
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
185
+ │ DOT-EUR │ 2023-10-14 04:00:00 │ 2023-10-17 14:00:00 │ 82 │ 100.946 │ -1.1753 │ -1.1643% │ 3.5643 │ 3.5228 │
186
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
187
+ │ DOT-EUR │ 2023-10-07 08:00:00 │ 2023-10-08 06:00:00 │ 22 │ 101.211 │ -1.0607 │ -1.0480% │ 3.874 │ 3.8334 │
188
+ ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
189
+ │ BTC-EUR │ 2023-09-27 10:00:00 │ 2023-10-05 20:00:00 │ 202 │ 97.4688 │ 4.0365 │ 4.1413% │ 24992 │ 26027 │
170
190
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
171
- │ BTC-EUR │ 2021-06-23 16:00:00 │ 2021-06-23 20:00:00 │ 4 │ 95.9956 │ -1.3022 │ -1.3565% │ 28234 │ 27851 │
191
+ │ DOT-EUR │ 2023-09-27 10:00:00 │ 2023-10-03 22:00:00 │ 156 │ 99.7074 │ 1.9774 │ 1.9832% │ 3.8271 │ 3.903 │
172
192
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
173
- │ BTC-EUR │ 2021-06-13 20:00:00 │ 2021-06-17 06:00:00 │ 82 │ 96.501 │ 1.014 │ 1.0508% │ 32167 │ 32505 │
193
+ │ DOT-EUR │ 2023-09-25 12:00:00 │ 2023-09-27 04:00:00 │ 40 │ 99.7994 │ -0.3672 │ -0.3679% │ 3.8052 │ 3.7912 │
174
194
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
175
- │ BTC-EUR │ 2021-06-09 20:00:00 │ 2021-06-12 18:00:00 │ 70 │ 95.3472 │ -1.424 │ -1.4935% │ 29796 │ 29351 │
195
+ │ DOT-EUR │ 2023-09-14 18:00:00 │ 2023-09-18 02:00:00 │ 80 │ 99.4298 │ -0.1612 │ -0.1621% │ 3.8244 │ 3.8182 │
176
196
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
177
- │ BTC-EUR │ 2021-05-31 20:00:00 │ 2021-06-04 18:00:00 │ 94 │ 96.4384 │ 1.0432 │ 1.0817% │ 30137 │ 30463 │
197
+ │ BTC-EUR │ 2023-09-12 16:00:00 │ 2023-09-21 18:00:00 │ 218 │ 98.008 │ 1.64 │ 1.6733% │ 24502 │ 24912 │
178
198
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
179
- │ BTC-EUR │ 2021-05-24 20:00:00 │ 2021-05-28 10:00:00 │ 86 │ 97.476 │ -6.732 │ -6.9063% │ 32492 │ 30248 │
199
+ │ BTC-EUR │ 2023-09-07 02:00:00 │ 2023-09-10 16:00:00 │ 86 │ 98.4656 │ 0.4592 │ 0.4664% │ 24016 │ 24128 │
180
200
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
181
- │ BTC-EUR │ 2021-05-07 16:00:00 │ 2021-05-10 22:00:00 │ 78 │ 95.296 │ -4.578 │ -4.8040% │ 47648 │ 45359 │
201
+ │ DOT-EUR │ 2023-09-07 00:00:00 │ 2023-09-09 02:00:00 │ 50 │ 99.3915 │ -0.307 │ -0.3089% │ 3.982 │ 3.9697 │
182
202
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
183
- │ BTC-EUR │ 2021-05-05 22:00:00 │ 2021-05-07 06:00:00 │ 32 │ 99.4392 │ -2.4423 │ -2.4561% │ 47352 │ 46189 │
203
+ │ BTC-EUR │ 2023-09-06 00:00:00 │ 2023-09-06 12:00:00 │ 12 │ 98.5558 │ -0.3116 │ -0.3162% │ 24038 │ 23962 │
184
204
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
185
- │ BTC-EUR │ 2021-04-30 14:00:00 │ 2021-05-04 06:00:00 │ 88 │ 97.4694 │ -0.1974 │ -0.2025% │ 46414 │ 46320 │
205
+ │ DOT-EUR │ 2023-09-05 12:00:00 │ 2023-09-06 16:00:00 │ 28 │ 99.6655 │ -0.7846 │ -0.7872% │ 3.9759 │ 3.9446 │
186
206
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
187
- │ BTC-EUR │ 2021-04-26 10:00:00 │ 2021-04-29 20:00:00 │ 82 │ 97.3544 │ -1.6874 │ -1.7333% │ 44252 │ 43485 │
207
+ │ BTC-EUR │ 2023-09-04 18:00:00 │ 2023-09-04 22:00:00 │ 4 │ 98.2565 │ -0.0164 │ -0.0167% │ 23965 │ 23961 │
188
208
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
189
- │ BTC-EUR │ 2021-04-09 10:00:00 │ 2021-04-16 12:00:00 │ 170 │ 98.1 │ 3.82 │ 3.8940% │ 49050 │ 50960 │
209
+ │ DOT-EUR │ 2023-09-04 08:00:00 │ 2023-09-04 22:00:00 │ 14 │ 99.9766 │ -1.2274 │ -1.2277% │ 3.9748 │ 3.926 │
190
210
  ├─────────┼─────────────────────┼─────────────────────┼────────────────────┼──────────────┼──────────────────┼───────────────────────┼────────────────────┼─────────────────────┤
191
- │ BTC-EUR │ 2021-04-06 04:00:00 │ 2021-04-06 16:00:00 │ 12 │ 99.678 │ -1.722 │ -1.7276% │ 49839 │ 48978 │
211
+ │ DOT-EUR │ 2023-08-25 02:00:00 │ 2023-08-25 10:00:00 │ 8 │ 99.9996 │ -0.0928 │ -0.0928% │ 4.0968 │ 4.093 │
192
212
  ╰─────────┴─────────────────────┴─────────────────────┴────────────────────┴──────────────┴──────────────────┴───────────────────────┴────────────────────┴─────────────────────╯
193
213
  ==================================================================
194
214
  ```
@@ -1,5 +1,6 @@
1
1
  import logging
2
2
  from typing import List
3
+ from queue import Queue
3
4
 
4
5
  from investing_algorithm_framework.domain import OrderStatus, OrderFee, \
5
6
  Position, Order, Portfolio, OrderType, OrderSide, ApiException, \
@@ -9,6 +10,49 @@ from investing_algorithm_framework.domain import OrderStatus, OrderFee, \
9
10
  logger = logging.getLogger("investing_algorithm_framework")
10
11
 
11
12
 
13
+ class PeekableQueue:
14
+ def __init__(self):
15
+ self.queue = []
16
+ self.index = 0
17
+
18
+ def enqueue(self, item):
19
+ self.queue.append(item)
20
+
21
+ def dequeue(self):
22
+ if not self.is_empty():
23
+ return self.queue.pop(0)
24
+ else:
25
+ raise IndexError("Queue is empty")
26
+
27
+ def peek(self):
28
+ if not self.is_empty():
29
+ return self.queue[0]
30
+ else:
31
+ raise IndexError("Queue is empty")
32
+
33
+ def is_empty(self):
34
+ return len(self.queue) == 0
35
+
36
+ def __len__(self):
37
+ return len(self.queue)
38
+
39
+ def size(self):
40
+ return len(self.queue)
41
+
42
+ def __iter__(self):
43
+ self.index = 0
44
+ return self
45
+
46
+ def __next__(self):
47
+ if self.index < len(self.queue):
48
+ result = self.queue[self.index]
49
+ self.index += 1
50
+ return result
51
+ else:
52
+ self.index = 0 # Reset index for next iteration
53
+ raise StopIteration
54
+
55
+
12
56
  class Algorithm:
13
57
 
14
58
  def __init__(
@@ -726,6 +770,7 @@ class Algorithm:
726
770
  def get_open_trades(self, target_symbol=None):
727
771
  portfolios = self.portfolio_service.get_all()
728
772
  trades = []
773
+
729
774
  for portfolio in portfolios:
730
775
 
731
776
  if target_symbol is not None:
@@ -735,38 +780,51 @@ class Algorithm:
735
780
  "portfolio_id": portfolio.id,
736
781
  "target_symbol": target_symbol
737
782
  })
783
+ sell_orders = self.order_service.get_all({
784
+ "status": OrderStatus.OPEN.value,
785
+ "order_side": OrderSide.SELL.value,
786
+ "portfolio_id": portfolio.id,
787
+ "target_symbol": target_symbol
788
+ })
738
789
  else:
739
790
  buy_orders = self.order_service.get_all({
740
791
  "status": OrderStatus.CLOSED.value,
741
792
  "order_side": OrderSide.BUY.value,
742
793
  "portfolio_id": portfolio.id
743
794
  })
795
+ sell_orders = self.order_service.get_all({
796
+ "status": OrderStatus.OPEN.value,
797
+ "order_side": OrderSide.SELL.value,
798
+ "portfolio_id": portfolio.id
799
+ })
800
+
744
801
  buy_orders = [
745
802
  buy_order for buy_order in buy_orders
746
803
  if buy_order.get_trade_closed_at() is None
747
804
  ]
748
- sell_orders = self.order_service.get_all({
749
- "status": OrderStatus.OPEN.value,
750
- "order_side": OrderSide.SELL.value,
751
- "portfolio_id": portfolio.id
752
- })
753
- sell_amount = sum([order.get_amount() for order in sell_orders])
805
+ sell_amount = sum([order.amount for order in sell_orders])
754
806
 
755
807
  # Subtract the amount of the open sell orders
756
808
  # from the amount of the buy orders
757
- while sell_amount > 0 and len(buy_orders) > 0:
758
- first_order = buy_orders[0]
809
+ buy_orders_queue = PeekableQueue()
759
810
 
760
- if first_order.get_available_amount() > sell_amount:
761
- first_order.set_available_amount(
762
- first_order.get_available_amount() - sell_amount
763
- )
811
+ for buy_order in buy_orders:
812
+ buy_orders_queue.enqueue(buy_order)
813
+
814
+ while sell_amount > 0 and not buy_orders_queue.is_empty():
815
+ first_buy_order = buy_orders_queue.peek()
816
+ available = first_buy_order.get_filled() \
817
+ - first_buy_order.get_trade_closed_amount()
818
+
819
+ if available > sell_amount:
820
+ remaining = available - sell_amount
764
821
  sell_amount = 0
822
+ first_buy_order.set_filled(remaining)
765
823
  else:
766
- sell_amount = sell_amount - first_order.get_available_amount()
767
- buy_orders.pop(0)
824
+ sell_amount = sell_amount - available
825
+ buy_orders_queue.dequeue()
768
826
 
769
- for buy_order in buy_orders:
827
+ for buy_order in buy_orders_queue:
770
828
  symbol = buy_order.get_symbol()
771
829
 
772
830
  try:
@@ -792,7 +850,8 @@ class Algorithm:
792
850
  buy_order_id=buy_order.id,
793
851
  target_symbol=buy_order.get_target_symbol(),
794
852
  trading_symbol=buy_order.get_trading_symbol(),
795
- amount=buy_order.get_amount(),
853
+ amount=buy_order.get_filled()
854
+ - buy_order.get_trade_closed_amount(),
796
855
  open_price=buy_order.get_price(),
797
856
  opened_at=buy_order.get_created_at(),
798
857
  current_price=ticker["bid"]
@@ -12,7 +12,8 @@ from .constants import ITEMIZE, ITEMIZED, PER_PAGE, PAGE, ENVIRONMENT, \
12
12
  DEFAULT_PAGE_VALUE, SQLALCHEMY_DATABASE_URI, RESOURCE_DIRECTORY, \
13
13
  DATETIME_FORMAT, DATETIME_FORMAT_BACKTESTING, BACKTESTING_FLAG, \
14
14
  BACKTESTING_INDEX_DATETIME, BACKTESTING_START_DATE, CCXT_DATETIME_FORMAT, \
15
- BACKTEST_DATA_DIRECTORY_NAME, TICKER_DATA_TYPE, OHLCV_DATA_TYPE
15
+ BACKTEST_DATA_DIRECTORY_NAME, TICKER_DATA_TYPE, OHLCV_DATA_TYPE, \
16
+ CURRENT_UTC_DATETIME
16
17
  from .singleton import Singleton
17
18
  from .utils import random_string, append_dict_as_row_to_csv, \
18
19
  add_column_headers_to_csv, get_total_amount_of_rows, \
@@ -90,5 +91,6 @@ __all__ = [
90
91
  "OHLCVMarketDataSource",
91
92
  "BacktestMarketDataSource",
92
93
  "BacktestPortfolioConfiguration",
93
- "MarketDataSource"
94
+ "MarketDataSource",
95
+ "CURRENT_UTC_DATETIME"
94
96
  ]
@@ -69,3 +69,4 @@ BACKTESTING_INDEX_DATETIME = "BACKTESTING_INDEX_DATETIME"
69
69
  BACKTESTING_START_DATE = "BACKTESTING_START_DATE"
70
70
  TICKER_DATA_TYPE = "TICKER"
71
71
  OHLCV_DATA_TYPE = "OHLCV"
72
+ CURRENT_UTC_DATETIME = "CURRENT_UTC_DATETIME"
@@ -79,7 +79,7 @@ class OrderBacktestService(OrderService):
79
79
  break
80
80
 
81
81
  def cancel_order(self, order):
82
- self.check_pending_orders(ohlcvs={})
82
+ self.check_pending_orders()
83
83
  order = self.order_repository.get(order.id)
84
84
 
85
85
  if order is not None:
@@ -651,12 +651,8 @@ class OrderService(RepositoryService):
651
651
 
652
652
  while amount_to_close > 0 and not order_queue.empty():
653
653
  buy_order = order_queue.get()
654
-
655
- if buy_order.get_trade_closed_amount() != None:
656
- available_to_close = buy_order.get_filled() \
657
- - buy_order.get_trade_closed_amount()
658
- else:
659
- available_to_close = buy_order.get_filled()
654
+ available_to_close = buy_order.get_filled() \
655
+ - buy_order.get_trade_closed_amount()
660
656
 
661
657
  if amount_to_close >= available_to_close:
662
658
  to_be_closed = available_to_close
@@ -682,7 +678,8 @@ class OrderService(RepositoryService):
682
678
  self.order_repository.update(
683
679
  buy_order.id,
684
680
  {
685
- "trade_closed_amount": buy_order.get_trade_closed_amount() + to_be_closed,
681
+ "trade_closed_amount":
682
+ buy_order.get_trade_closed_amount() + to_be_closed,
686
683
  "trade_closed_price": sell_order.get_price(),
687
684
  "net_gain": buy_order.get_net_gain() + net_gain
688
685
  }