investing-algorithm-framework 1.4.4__tar.gz → 1.5__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.4.4 → investing_algorithm_framework-1.5}/PKG-INFO +81 -23
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/README.md +79 -22
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/__init__.py +5 -3
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/algorithm.py +165 -100
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/app.py +191 -70
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/strategy.py +15 -1
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/web/schemas/order.py +2 -2
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/create_app.py +2 -1
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/dependency_container.py +43 -3
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/__init__.py +21 -3
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/config.py +52 -53
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/constants.py +9 -1
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/__init__.py +12 -3
- investing_algorithm_framework-1.5/investing_algorithm_framework/domain/models/backtest_profile.py +414 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/market_data/ohlcv.py +33 -4
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/order/order.py +44 -73
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/order/order_fee.py +2 -6
- investing_algorithm_framework-1.5/investing_algorithm_framework/domain/models/portfolio/__init__.py +5 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/portfolio/portfolio.py +27 -16
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/portfolio/portfolio_configuration.py +8 -2
- investing_algorithm_framework-1.5/investing_algorithm_framework/domain/models/portfolio/portfolio_snapshot.py +111 -0
- investing_algorithm_framework-1.5/investing_algorithm_framework/domain/models/position/__init__.py +4 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/position/position.py +3 -4
- investing_algorithm_framework-1.4.4/investing_algorithm_framework/domain/models/position/position_cost.py → investing_algorithm_framework-1.5/investing_algorithm_framework/domain/models/position/position_snapshot.py +19 -23
- investing_algorithm_framework-1.5/investing_algorithm_framework/domain/models/strategy_profile.py +155 -0
- investing_algorithm_framework-1.5/investing_algorithm_framework/domain/models/time_unit.py +85 -0
- investing_algorithm_framework-1.5/investing_algorithm_framework/domain/models/trade.py +78 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/trading_time_frame.py +18 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/utils/__init__.py +3 -1
- investing_algorithm_framework-1.5/investing_algorithm_framework/domain/utils/backtesting.py +82 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/__init__.py +7 -2
- investing_algorithm_framework-1.5/investing_algorithm_framework/infrastructure/models/__init__.py +12 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/models/order/order.py +52 -15
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/models/order/order_fee.py +3 -3
- investing_algorithm_framework-1.5/investing_algorithm_framework/infrastructure/models/portfolio/__init__.py +4 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/models/portfolio/portfolio.py +37 -27
- investing_algorithm_framework-1.5/investing_algorithm_framework/infrastructure/models/portfolio/portfolio_snapshot.py +31 -0
- investing_algorithm_framework-1.5/investing_algorithm_framework/infrastructure/models/position/__init__.py +4 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/models/position/position.py +9 -10
- investing_algorithm_framework-1.5/investing_algorithm_framework/infrastructure/models/position/position_snapshot.py +21 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/repositories/__init__.py +4 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/repositories/order_repository.py +15 -13
- investing_algorithm_framework-1.5/investing_algorithm_framework/infrastructure/repositories/portfolio_snapshot_repository.py +56 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/repositories/position_repository.py +2 -3
- investing_algorithm_framework-1.5/investing_algorithm_framework/infrastructure/repositories/position_snapshot_repository.py +21 -0
- investing_algorithm_framework-1.5/investing_algorithm_framework/infrastructure/services/__init__.py +5 -0
- investing_algorithm_framework-1.5/investing_algorithm_framework/infrastructure/services/market_backtest_service.py +360 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/services/market_service.py +33 -14
- investing_algorithm_framework-1.5/investing_algorithm_framework/infrastructure/services/performance_backtest_service.py +0 -0
- investing_algorithm_framework-1.5/investing_algorithm_framework/infrastructure/services/performance_service.py +192 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/services/__init__.py +11 -0
- investing_algorithm_framework-1.5/investing_algorithm_framework/services/backtest_service.py +268 -0
- investing_algorithm_framework-1.5/investing_algorithm_framework/services/configuration_service.py +29 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/services/market_data_service.py +7 -5
- investing_algorithm_framework-1.5/investing_algorithm_framework/services/order_backtest_service.py +122 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/services/order_service.py +107 -43
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/services/portfolio_service.py +28 -3
- investing_algorithm_framework-1.5/investing_algorithm_framework/services/portfolio_snapshot_service.py +68 -0
- investing_algorithm_framework-1.5/investing_algorithm_framework/services/position_snapshot_service.py +18 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework.egg-info/PKG-INFO +81 -23
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework.egg-info/SOURCES.txt +18 -1
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework.egg-info/requires.txt +1 -0
- investing_algorithm_framework-1.4.4/investing_algorithm_framework/domain/models/portfolio/__init__.py +0 -4
- investing_algorithm_framework-1.4.4/investing_algorithm_framework/domain/models/position/__init__.py +0 -3
- investing_algorithm_framework-1.4.4/investing_algorithm_framework/domain/models/time_unit.py +0 -40
- investing_algorithm_framework-1.4.4/investing_algorithm_framework/infrastructure/models/__init__.py +0 -7
- investing_algorithm_framework-1.4.4/investing_algorithm_framework/infrastructure/models/portfolio/__init__.py +0 -3
- investing_algorithm_framework-1.4.4/investing_algorithm_framework/infrastructure/models/position/__init__.py +0 -3
- investing_algorithm_framework-1.4.4/investing_algorithm_framework/infrastructure/services/__init__.py +0 -3
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/AUTHORS.md +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/LICENSE +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/__init__.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/stateless/__init__.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/stateless/action_handlers/__init__.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/stateless/action_handlers/action_handler_strategy.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/stateless/action_handlers/check_online_handler.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/stateless/action_handlers/run_strategy_handler.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/stateless/exception_handler.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/task.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/web/__init__.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/web/controllers/__init__.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/web/controllers/orders.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/web/controllers/portfolio.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/web/controllers/positions.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/web/create_app.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/web/error_handler.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/web/responses.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/web/run_strategies.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/web/schemas/__init__.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/web/schemas/portfolio.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/web/schemas/position.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/app/web/setup_cors.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/decimal_parsing.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/exceptions.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/base_model.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/market_data/__init__.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/market_data/asset_price.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/market_data/order_book.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/market_data/ticker.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/order/__init__.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/order/order_side.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/order/order_status.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/order/order_type.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/time_frame.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/time_interval.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/models/trading_data_types.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/singleton.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/stateless_actions.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/strategy.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/utils/csv.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/utils/random.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/utils/signatures.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/utils/stoppable_thread.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/domain/utils/synchronized.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/database/__init__.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/database/sql_alchemy.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/models/decimal_parser.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/models/model_extension.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/models/order/__init__.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/repositories/order_fee_repository.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/repositories/portfolio_repository.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/infrastructure/repositories/repository.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/services/portfolio_configuration_service.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/services/position_cost_service.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/services/position_service.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/services/repository_service.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework/services/strategy_orchestrator_service.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework.egg-info/dependency_links.txt +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/investing_algorithm_framework.egg-info/top_level.txt +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/setup.cfg +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/setup.py +0 -0
- {investing_algorithm_framework-1.4.4 → investing_algorithm_framework-1.5}/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.
|
|
3
|
+
Version: 1.5
|
|
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
|
|
@@ -32,6 +32,7 @@ Requires-Dist: MarkupSafe==2.1.2
|
|
|
32
32
|
Requires-Dist: dependency-injector==4.40.0
|
|
33
33
|
Requires-Dist: schedule==1.1.0
|
|
34
34
|
Requires-Dist: pandas==2.0.0
|
|
35
|
+
Requires-Dist: tqdm==4.66.1
|
|
35
36
|
|
|
36
37
|
<a href=https://investing-algorithm-framework.com><img src="https://img.shields.io/badge/docs-website-brightgreen"></a>
|
|
37
38
|
[](https://github.com/coding-kitties/investing-algorithm-framework/actions/workflows/build.yml)
|
|
@@ -41,8 +42,8 @@ Requires-Dist: pandas==2.0.0
|
|
|
41
42
|
<a href="https://www.reddit.com/r/InvestingBots/"><img src="https://img.shields.io/reddit/subreddit-subscribers/investingbots?style=social"></a>
|
|
42
43
|
###### Sponsors
|
|
43
44
|
<p align="left">
|
|
44
|
-
<a href="https://
|
|
45
|
-
<img alt="
|
|
45
|
+
<a href="https://finterion.com">
|
|
46
|
+
<img alt="Finterion" src="https://logicfunds-web-app-images.s3.eu-central-1.amazonaws.com/finterion.png" width="200px" />
|
|
46
47
|
</a>
|
|
47
48
|
</p>
|
|
48
49
|
|
|
@@ -54,7 +55,7 @@ elegant development of investment algorithms and trading bots. It comes with all
|
|
|
54
55
|
components for creating algorithms, including data provisioning, portfolio management, and order execution.
|
|
55
56
|
|
|
56
57
|
|
|
57
|
-
## Example
|
|
58
|
+
## Example implementation
|
|
58
59
|
The following algorithm connects to binance and buys BTC every 5 seconds.
|
|
59
60
|
It also exposes an REST API that allows you to interact with the algorithm.
|
|
60
61
|
```python
|
|
@@ -67,7 +68,7 @@ from investing_algorithm_framework import create_app, PortfolioConfiguration, \
|
|
|
67
68
|
app = create_app({RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()})
|
|
68
69
|
app.add_portfolio_configuration(
|
|
69
70
|
PortfolioConfiguration(
|
|
70
|
-
market="
|
|
71
|
+
market="BITVAVO",
|
|
71
72
|
api_key="xxxxxx",
|
|
72
73
|
secret_key="xxxxxx",
|
|
73
74
|
trading_symbol="USDT"
|
|
@@ -76,25 +77,30 @@ app.add_portfolio_configuration(
|
|
|
76
77
|
|
|
77
78
|
|
|
78
79
|
@app.strategy(
|
|
79
|
-
time_unit=TimeUnit.
|
|
80
|
-
interval=
|
|
81
|
-
market="
|
|
82
|
-
symbols=["BTC/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
time_unit=TimeUnit.HOUR, # Algorithm will be executed every 2 hours
|
|
81
|
+
interval=2,
|
|
82
|
+
market="BITVAVO", # Will retrieve trading data from binance
|
|
83
|
+
symbols=["BTC/EUR", "ETH/EUR", "DOT/EUR"],
|
|
84
|
+
# Symbols must be in the format of TARGET/TRADE symbol (e.g. BTC/USDT)
|
|
85
|
+
trading_data_types=[TradingDataType.OHLCV, TradingDataType.TICKER],
|
|
86
|
+
trading_time_frame_start_date=datetime.utcnow() - timedelta(days=1),
|
|
87
|
+
# Will retrieve data from the last 24 hours
|
|
88
|
+
trading_time_frame=TradingTimeFrame.ONE_MINUTE
|
|
89
|
+
# Will retrieve data on 1m interval (OHLCV)
|
|
86
90
|
)
|
|
87
91
|
def perform_strategy(algorithm, market_data):
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
algorithm.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
92
|
+
target_symbol = "BTC"
|
|
93
|
+
price = market_data[TradingDataType.TICKER]["BTC/EUR"]["bid"]
|
|
94
|
+
|
|
95
|
+
if not algorithm.has_open_orders(target_symbol) and \
|
|
96
|
+
not algorithm.has_position(target_symbol):
|
|
97
|
+
algorithm.create_limit_order(
|
|
98
|
+
target_symbol,
|
|
99
|
+
order_side=OrderSide.BUY,
|
|
100
|
+
percentage_of_portfolio=25,
|
|
101
|
+
# You can also use amount instead of percentage_of_portfolio
|
|
102
|
+
price=price
|
|
103
|
+
)
|
|
98
104
|
|
|
99
105
|
if __name__ == "__main__":
|
|
100
106
|
app.run()
|
|
@@ -102,6 +108,58 @@ if __name__ == "__main__":
|
|
|
102
108
|
|
|
103
109
|
> You can find more examples [here](./examples) folder.
|
|
104
110
|
|
|
111
|
+
## Backtesting
|
|
112
|
+
The framework also supports backtesting. You can use the same code as above,
|
|
113
|
+
but instead of running the algorithm, you can run a backtest.
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
import pathlib
|
|
117
|
+
from datetime import datetime, timedelta
|
|
118
|
+
|
|
119
|
+
from investing_algorithm_framework import create_app, OrderSide, \
|
|
120
|
+
RESOURCE_DIRECTORY, TimeUnit, TradingTimeFrame, TradingDataType, \
|
|
121
|
+
pretty_print_backtest
|
|
122
|
+
|
|
123
|
+
app = create_app({RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()})
|
|
124
|
+
|
|
125
|
+
@app.strategy(
|
|
126
|
+
time_unit=TimeUnit.HOUR, # Algorithm will be executed every 2 hours
|
|
127
|
+
interval=2,
|
|
128
|
+
market="BITVAVO", # Will retrieve trading data from binance
|
|
129
|
+
symbols=["BTC/EUR", "ETH/EUR", "DOT/EUR"],
|
|
130
|
+
# Symbols must be in the format of TARGET/TRADE symbol (e.g. BTC/USDT)
|
|
131
|
+
trading_data_types=[TradingDataType.OHLCV, TradingDataType.TICKER],
|
|
132
|
+
trading_time_frame_start_date=datetime.utcnow() - timedelta(days=1),
|
|
133
|
+
# Will retrieve data from the last 24 hours
|
|
134
|
+
trading_time_frame=TradingTimeFrame.ONE_MINUTE
|
|
135
|
+
# Will retrieve data on 1m interval (OHLCV)
|
|
136
|
+
)
|
|
137
|
+
def perform_strategy(algorithm, market_data):
|
|
138
|
+
target_symbol = "BTC"
|
|
139
|
+
price = market_data[TradingDataType.TICKER]["BTC/EUR"]["bid"]
|
|
140
|
+
|
|
141
|
+
if not algorithm.has_open_orders(target_symbol) and \
|
|
142
|
+
not algorithm.has_position(target_symbol):
|
|
143
|
+
algorithm.create_limit_order(
|
|
144
|
+
target_symbol,
|
|
145
|
+
order_side=OrderSide.BUY,
|
|
146
|
+
percentage_of_portfolio=25,
|
|
147
|
+
# You can also use amount instead of percentage_of_portfolio
|
|
148
|
+
price=price
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
if __name__ == "__main__":
|
|
153
|
+
backtest_report = app.backtest(
|
|
154
|
+
start_date=datetime(2023, 11, 12) - timedelta(days=10),
|
|
155
|
+
end_date=datetime(2023, 11, 12),
|
|
156
|
+
unallocated=400,
|
|
157
|
+
trading_symbol="EUR"
|
|
158
|
+
)
|
|
159
|
+
pretty_print_backtest(backtest_report)
|
|
160
|
+
```
|
|
161
|
+
For more examples, check out the [examples](./examples/backtesting) folder.
|
|
162
|
+
|
|
105
163
|
## Broker/Exchange configuration
|
|
106
164
|
The framework has by default support for [ccxt](https://github.com/ccxt/ccxt).
|
|
107
165
|
This should allow you to connect to a lot of brokers/exchanges.
|
|
@@ -111,7 +169,7 @@ from investing_algorithm_framework import App, PortfolioConfiguration
|
|
|
111
169
|
app = App()
|
|
112
170
|
app.add_portfolio_configuration(
|
|
113
171
|
PortfolioConfiguration(
|
|
114
|
-
market="
|
|
172
|
+
market="BITVAVO",
|
|
115
173
|
api_key="xxxx",
|
|
116
174
|
secret_key="xxxx",
|
|
117
175
|
track_from="01/01/2022",
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
<a href="https://www.reddit.com/r/InvestingBots/"><img src="https://img.shields.io/reddit/subreddit-subscribers/investingbots?style=social"></a>
|
|
7
7
|
###### Sponsors
|
|
8
8
|
<p align="left">
|
|
9
|
-
<a href="https://
|
|
10
|
-
<img alt="
|
|
9
|
+
<a href="https://finterion.com">
|
|
10
|
+
<img alt="Finterion" src="https://logicfunds-web-app-images.s3.eu-central-1.amazonaws.com/finterion.png" width="200px" />
|
|
11
11
|
</a>
|
|
12
12
|
</p>
|
|
13
13
|
|
|
@@ -19,7 +19,7 @@ elegant development of investment algorithms and trading bots. It comes with all
|
|
|
19
19
|
components for creating algorithms, including data provisioning, portfolio management, and order execution.
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
## Example
|
|
22
|
+
## Example implementation
|
|
23
23
|
The following algorithm connects to binance and buys BTC every 5 seconds.
|
|
24
24
|
It also exposes an REST API that allows you to interact with the algorithm.
|
|
25
25
|
```python
|
|
@@ -32,7 +32,7 @@ from investing_algorithm_framework import create_app, PortfolioConfiguration, \
|
|
|
32
32
|
app = create_app({RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()})
|
|
33
33
|
app.add_portfolio_configuration(
|
|
34
34
|
PortfolioConfiguration(
|
|
35
|
-
market="
|
|
35
|
+
market="BITVAVO",
|
|
36
36
|
api_key="xxxxxx",
|
|
37
37
|
secret_key="xxxxxx",
|
|
38
38
|
trading_symbol="USDT"
|
|
@@ -41,25 +41,30 @@ app.add_portfolio_configuration(
|
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
@app.strategy(
|
|
44
|
-
time_unit=TimeUnit.
|
|
45
|
-
interval=
|
|
46
|
-
market="
|
|
47
|
-
symbols=["BTC/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
time_unit=TimeUnit.HOUR, # Algorithm will be executed every 2 hours
|
|
45
|
+
interval=2,
|
|
46
|
+
market="BITVAVO", # Will retrieve trading data from binance
|
|
47
|
+
symbols=["BTC/EUR", "ETH/EUR", "DOT/EUR"],
|
|
48
|
+
# Symbols must be in the format of TARGET/TRADE symbol (e.g. BTC/USDT)
|
|
49
|
+
trading_data_types=[TradingDataType.OHLCV, TradingDataType.TICKER],
|
|
50
|
+
trading_time_frame_start_date=datetime.utcnow() - timedelta(days=1),
|
|
51
|
+
# Will retrieve data from the last 24 hours
|
|
52
|
+
trading_time_frame=TradingTimeFrame.ONE_MINUTE
|
|
53
|
+
# Will retrieve data on 1m interval (OHLCV)
|
|
51
54
|
)
|
|
52
55
|
def perform_strategy(algorithm, market_data):
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
algorithm.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
target_symbol = "BTC"
|
|
57
|
+
price = market_data[TradingDataType.TICKER]["BTC/EUR"]["bid"]
|
|
58
|
+
|
|
59
|
+
if not algorithm.has_open_orders(target_symbol) and \
|
|
60
|
+
not algorithm.has_position(target_symbol):
|
|
61
|
+
algorithm.create_limit_order(
|
|
62
|
+
target_symbol,
|
|
63
|
+
order_side=OrderSide.BUY,
|
|
64
|
+
percentage_of_portfolio=25,
|
|
65
|
+
# You can also use amount instead of percentage_of_portfolio
|
|
66
|
+
price=price
|
|
67
|
+
)
|
|
63
68
|
|
|
64
69
|
if __name__ == "__main__":
|
|
65
70
|
app.run()
|
|
@@ -67,6 +72,58 @@ if __name__ == "__main__":
|
|
|
67
72
|
|
|
68
73
|
> You can find more examples [here](./examples) folder.
|
|
69
74
|
|
|
75
|
+
## Backtesting
|
|
76
|
+
The framework also supports backtesting. You can use the same code as above,
|
|
77
|
+
but instead of running the algorithm, you can run a backtest.
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import pathlib
|
|
81
|
+
from datetime import datetime, timedelta
|
|
82
|
+
|
|
83
|
+
from investing_algorithm_framework import create_app, OrderSide, \
|
|
84
|
+
RESOURCE_DIRECTORY, TimeUnit, TradingTimeFrame, TradingDataType, \
|
|
85
|
+
pretty_print_backtest
|
|
86
|
+
|
|
87
|
+
app = create_app({RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()})
|
|
88
|
+
|
|
89
|
+
@app.strategy(
|
|
90
|
+
time_unit=TimeUnit.HOUR, # Algorithm will be executed every 2 hours
|
|
91
|
+
interval=2,
|
|
92
|
+
market="BITVAVO", # Will retrieve trading data from binance
|
|
93
|
+
symbols=["BTC/EUR", "ETH/EUR", "DOT/EUR"],
|
|
94
|
+
# Symbols must be in the format of TARGET/TRADE symbol (e.g. BTC/USDT)
|
|
95
|
+
trading_data_types=[TradingDataType.OHLCV, TradingDataType.TICKER],
|
|
96
|
+
trading_time_frame_start_date=datetime.utcnow() - timedelta(days=1),
|
|
97
|
+
# Will retrieve data from the last 24 hours
|
|
98
|
+
trading_time_frame=TradingTimeFrame.ONE_MINUTE
|
|
99
|
+
# Will retrieve data on 1m interval (OHLCV)
|
|
100
|
+
)
|
|
101
|
+
def perform_strategy(algorithm, market_data):
|
|
102
|
+
target_symbol = "BTC"
|
|
103
|
+
price = market_data[TradingDataType.TICKER]["BTC/EUR"]["bid"]
|
|
104
|
+
|
|
105
|
+
if not algorithm.has_open_orders(target_symbol) and \
|
|
106
|
+
not algorithm.has_position(target_symbol):
|
|
107
|
+
algorithm.create_limit_order(
|
|
108
|
+
target_symbol,
|
|
109
|
+
order_side=OrderSide.BUY,
|
|
110
|
+
percentage_of_portfolio=25,
|
|
111
|
+
# You can also use amount instead of percentage_of_portfolio
|
|
112
|
+
price=price
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
if __name__ == "__main__":
|
|
117
|
+
backtest_report = app.backtest(
|
|
118
|
+
start_date=datetime(2023, 11, 12) - timedelta(days=10),
|
|
119
|
+
end_date=datetime(2023, 11, 12),
|
|
120
|
+
unallocated=400,
|
|
121
|
+
trading_symbol="EUR"
|
|
122
|
+
)
|
|
123
|
+
pretty_print_backtest(backtest_report)
|
|
124
|
+
```
|
|
125
|
+
For more examples, check out the [examples](./examples/backtesting) folder.
|
|
126
|
+
|
|
70
127
|
## Broker/Exchange configuration
|
|
71
128
|
The framework has by default support for [ccxt](https://github.com/ccxt/ccxt).
|
|
72
129
|
This should allow you to connect to a lot of brokers/exchanges.
|
|
@@ -76,7 +133,7 @@ from investing_algorithm_framework import App, PortfolioConfiguration
|
|
|
76
133
|
app = App()
|
|
77
134
|
app.add_portfolio_configuration(
|
|
78
135
|
PortfolioConfiguration(
|
|
79
|
-
market="
|
|
136
|
+
market="BITVAVO",
|
|
80
137
|
api_key="xxxx",
|
|
81
138
|
secret_key="xxxx",
|
|
82
139
|
track_from="01/01/2022",
|
|
@@ -3,9 +3,9 @@ from .create_app import create_app
|
|
|
3
3
|
from investing_algorithm_framework.domain import ApiException, \
|
|
4
4
|
TradingDataType, OrderBook, Ticker, TradingTimeFrame, OHLCV, OrderType,\
|
|
5
5
|
OrderStatus, OrderSide, Config, TimeUnit, TimeInterval, Order, Portfolio, \
|
|
6
|
-
Position
|
|
6
|
+
Position, TimeFrame, BACKTESTING_INDEX_DATETIME
|
|
7
7
|
from investing_algorithm_framework.domain import PortfolioConfiguration, \
|
|
8
|
-
RESOURCE_DIRECTORY
|
|
8
|
+
RESOURCE_DIRECTORY, pretty_print_backtest
|
|
9
9
|
from investing_algorithm_framework.app import TradingStrategy, \
|
|
10
10
|
StatelessAction, Task
|
|
11
11
|
|
|
@@ -32,5 +32,7 @@ __all__ = [
|
|
|
32
32
|
"Portfolio",
|
|
33
33
|
"Position",
|
|
34
34
|
"StatelessAction",
|
|
35
|
-
"Task"
|
|
35
|
+
"Task",
|
|
36
|
+
"pretty_print_backtest",
|
|
37
|
+
"BACKTESTING_INDEX_DATETIME"
|
|
36
38
|
]
|