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.
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/PKG-INFO +51 -31
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/README.md +50 -30
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/algorithm.py +75 -16
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/__init__.py +4 -2
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/constants.py +1 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/order_backtest_service.py +1 -1
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/order_service.py +4 -7
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework.egg-info/PKG-INFO +51 -31
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/AUTHORS.md +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/LICENSE +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/app.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/stateless/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/stateless/action_handlers/__init__.py +0 -0
- {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
- {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
- {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
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/stateless/exception_handler.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/strategy.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/task.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/controllers/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/controllers/orders.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/controllers/portfolio.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/controllers/positions.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/create_app.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/error_handler.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/responses.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/run_strategies.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/schemas/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/schemas/order.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/schemas/portfolio.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/schemas/position.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/app/web/setup_cors.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/create_app.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/dependency_container.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/config.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/decimal_parsing.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/exceptions.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/backtest_profile.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/base_model.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/market_data/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/market_data/asset_price.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/market_data/ohlcv.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/market_data/order_book.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/market_data/ticker.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/order.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/order_fee.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/order_side.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/order_status.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/order/order_type.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/portfolio/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/portfolio/backtest_portfolio_configuration.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/portfolio/portfolio.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/portfolio/portfolio_configuration.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/portfolio/portfolio_snapshot.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/position/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/position/position.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/position/position_snapshot.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/strategy_profile.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/time_frame.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/time_interval.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/time_unit.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/trade.py +1 -1
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/trading_data_types.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/models/trading_time_frame.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/services/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/services/market_data_sources.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/services/order_executor_service.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/singleton.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/stateless_actions.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/strategy.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/backtesting.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/csv.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/random.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/signatures.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/stoppable_thread.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/domain/utils/synchronized.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/database/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/database/sql_alchemy.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/decimal_parser.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/market_data_sources/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/market_data_sources/csv.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/model_extension.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/order/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/order/order.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/order/order_fee.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/portfolio/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/portfolio/portfolio.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/portfolio/portfolio_snapshot.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/position/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/position/position.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/models/position/position_snapshot.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/order_fee_repository.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/order_repository.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/portfolio_repository.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/portfolio_snapshot_repository.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/position_repository.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/position_snapshot_repository.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/repositories/repository.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/market_service/__init__.py +0 -0
- {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
- {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
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/market_service/market_service.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/performance_service/__init__.py +0 -0
- {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
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/infrastructure/services/performance_service/performance_service.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/__init__.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/backtest_service.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/configuration_service.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/market_data_service.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/portfolio_configuration_service.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/portfolio_service.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/portfolio_snapshot_service.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/position_cost_service.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/position_service.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/position_snapshot_service.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/repository_service.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework/services/strategy_orchestrator_service.py +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework.egg-info/SOURCES.txt +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework.egg-info/dependency_links.txt +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework.egg-info/requires.txt +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/investing_algorithm_framework.egg-info/top_level.txt +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/setup.cfg +0 -0
- {investing_algorithm_framework-1.7.8 → investing_algorithm_framework-1.7.10}/setup.py +0 -0
- {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.
|
|
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
|
|
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:
|
|
179
|
-
* End date:
|
|
180
|
-
* Number of days:
|
|
181
|
-
* Number of runs:
|
|
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:
|
|
183
|
+
* Number of orders: 41
|
|
184
184
|
* Initial balance: 400.0000 EUR
|
|
185
|
-
* Final balance:
|
|
186
|
-
* Total net gain:
|
|
187
|
-
* Total net gain percentage:
|
|
188
|
-
* Growth rate:
|
|
189
|
-
* Growth
|
|
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 │
|
|
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:
|
|
198
|
-
* Number of trades open:
|
|
199
|
-
* Percentage of positive trades:
|
|
200
|
-
* Percentage of negative trades:
|
|
201
|
-
* Average trade size:
|
|
202
|
-
* Average trade duration:
|
|
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
|
-
│
|
|
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
|
-
│
|
|
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
|
-
│
|
|
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
|
-
│
|
|
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 │
|
|
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 │
|
|
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
|
-
│
|
|
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 │
|
|
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
|
-
│
|
|
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 │
|
|
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
|
-
│
|
|
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
|
-
│
|
|
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
|
|
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:
|
|
142
|
-
* End date:
|
|
143
|
-
* Number of days:
|
|
144
|
-
* Number of runs:
|
|
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:
|
|
146
|
+
* Number of orders: 41
|
|
147
147
|
* Initial balance: 400.0000 EUR
|
|
148
|
-
* Final balance:
|
|
149
|
-
* Total net gain:
|
|
150
|
-
* Total net gain percentage:
|
|
151
|
-
* Growth rate:
|
|
152
|
-
* Growth
|
|
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 │
|
|
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:
|
|
161
|
-
* Number of trades open:
|
|
162
|
-
* Percentage of positive trades:
|
|
163
|
-
* Percentage of negative trades:
|
|
164
|
-
* Average trade size:
|
|
165
|
-
* Average trade duration:
|
|
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
|
-
│
|
|
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
|
-
│
|
|
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
|
-
│
|
|
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
|
-
│
|
|
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 │
|
|
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 │
|
|
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
|
-
│
|
|
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 │
|
|
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
|
-
│
|
|
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 │
|
|
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
|
-
│
|
|
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
|
-
│
|
|
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
|
-
|
|
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
|
-
|
|
758
|
-
first_order = buy_orders[0]
|
|
809
|
+
buy_orders_queue = PeekableQueue()
|
|
759
810
|
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
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 -
|
|
767
|
-
|
|
824
|
+
sell_amount = sell_amount - available
|
|
825
|
+
buy_orders_queue.dequeue()
|
|
768
826
|
|
|
769
|
-
for buy_order in
|
|
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.
|
|
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
|
]
|
|
@@ -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
|
-
|
|
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":
|
|
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
|
}
|