investing-algorithm-framework 1.7__tar.gz → 1.7.2__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 → investing_algorithm_framework-1.7.2}/PKG-INFO +5 -13
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/README.md +4 -12
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/algorithm.py +89 -58
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/order/order.py +16 -9
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/models/market_data_sources/ccxt.py +8 -6
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/models/order/order.py +1 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework.egg-info/PKG-INFO +5 -13
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/AUTHORS.md +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/LICENSE +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/app.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/stateless/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/stateless/action_handlers/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/stateless/action_handlers/action_handler_strategy.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/stateless/action_handlers/check_online_handler.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/stateless/action_handlers/run_strategy_handler.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/stateless/exception_handler.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/strategy.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/task.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/web/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/web/controllers/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/web/controllers/orders.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/web/controllers/portfolio.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/web/controllers/positions.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/web/create_app.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/web/error_handler.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/web/responses.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/web/run_strategies.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/web/schemas/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/web/schemas/order.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/web/schemas/portfolio.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/web/schemas/position.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/app/web/setup_cors.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/create_app.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/dependency_container.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/config.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/constants.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/decimal_parsing.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/exceptions.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/backtest_profile.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/base_model.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/market_data/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/market_data/asset_price.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/market_data/ohlcv.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/market_data/order_book.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/market_data/ticker.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/order/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/order/order_fee.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/order/order_side.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/order/order_status.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/order/order_type.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/portfolio/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/portfolio/portfolio.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/portfolio/portfolio_configuration.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/portfolio/portfolio_snapshot.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/position/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/position/position.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/position/position_snapshot.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/strategy_profile.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/time_frame.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/time_interval.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/time_unit.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/trade.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/trading_data_types.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/models/trading_time_frame.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/services/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/services/market_data_sources.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/singleton.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/stateless_actions.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/strategy.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/utils/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/utils/backtesting.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/utils/csv.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/utils/random.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/utils/signatures.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/utils/stoppable_thread.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/domain/utils/synchronized.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/database/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/database/sql_alchemy.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/models/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/models/decimal_parser.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/models/market_data_sources/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/models/model_extension.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/models/order/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/models/order/order_fee.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/models/portfolio/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/models/portfolio/portfolio.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/models/portfolio/portfolio_snapshot.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/models/position/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/models/position/position.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/models/position/position_snapshot.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/repositories/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/repositories/order_fee_repository.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/repositories/order_repository.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/repositories/portfolio_repository.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/repositories/portfolio_snapshot_repository.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/repositories/position_repository.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/repositories/position_snapshot_repository.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/repositories/repository.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/services/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/services/ccxt_market_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/services/market_backtest_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/services/market_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/services/performance_backtest_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/infrastructure/services/performance_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/services/__init__.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/services/backtest_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/services/configuration_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/services/market_data_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/services/order_backtest_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/services/order_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/services/portfolio_configuration_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/services/portfolio_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/services/portfolio_snapshot_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/services/position_cost_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/services/position_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/services/position_snapshot_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/services/repository_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework/services/strategy_orchestrator_service.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework.egg-info/SOURCES.txt +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework.egg-info/dependency_links.txt +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework.egg-info/requires.txt +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/investing_algorithm_framework.egg-info/top_level.txt +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/setup.cfg +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/setup.py +0 -0
- {investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/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.2
|
|
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
|
|
@@ -62,20 +62,16 @@ It also exposes an REST API that allows you to interact with the algorithm.
|
|
|
62
62
|
```python
|
|
63
63
|
import pathlib
|
|
64
64
|
from datetime import datetime, timedelta
|
|
65
|
-
|
|
66
65
|
from investing_algorithm_framework import create_app, PortfolioConfiguration, \
|
|
67
66
|
RESOURCE_DIRECTORY, TimeUnit, CCXTOHLCVMarketDataSource, Algorithm
|
|
68
67
|
|
|
69
|
-
def start_date_func():
|
|
70
|
-
return datetime.utcnow() - timedelta(days=17)
|
|
71
|
-
|
|
72
68
|
# Define market data sources
|
|
73
69
|
bitvavo_btc_eur_ohlcv_2h = CCXTOHLCVMarketDataSource(
|
|
74
70
|
identifier="BTC",
|
|
75
71
|
market="BITVAVO",
|
|
76
72
|
symbol="BTC/EUR",
|
|
77
73
|
timeframe="2h",
|
|
78
|
-
start_date_func=
|
|
74
|
+
start_date_func=lambda : datetime.utcnow() - timedelta(days=17)
|
|
79
75
|
)
|
|
80
76
|
app = create_app({RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()})
|
|
81
77
|
app.add_portfolio_configuration(
|
|
@@ -83,7 +79,7 @@ app.add_portfolio_configuration(
|
|
|
83
79
|
market="BITVAVO",
|
|
84
80
|
api_key="<your api key>",
|
|
85
81
|
secret_key="<your secret key>",
|
|
86
|
-
trading_symbol="
|
|
82
|
+
trading_symbol="EUR"
|
|
87
83
|
)
|
|
88
84
|
)
|
|
89
85
|
|
|
@@ -112,12 +108,8 @@ but instead of running the algorithm, you can run a backtest.
|
|
|
112
108
|
```python
|
|
113
109
|
import pathlib
|
|
114
110
|
from datetime import datetime, timedelta
|
|
115
|
-
|
|
116
111
|
from investing_algorithm_framework import create_app, RESOURCE_DIRECTORY, \
|
|
117
|
-
TimeUnit, CCXTOHLCVMarketDataSource, Algorithm
|
|
118
|
-
|
|
119
|
-
def start_date_func():
|
|
120
|
-
return datetime.utcnow() - timedelta(days=17)
|
|
112
|
+
TimeUnit, CCXTOHLCVMarketDataSource, Algorithm, pretty_print_backtest
|
|
121
113
|
|
|
122
114
|
# Define market data sources
|
|
123
115
|
bitvavo_btc_eur_ohlcv_2h = CCXTOHLCVMarketDataSource(
|
|
@@ -125,7 +117,7 @@ bitvavo_btc_eur_ohlcv_2h = CCXTOHLCVMarketDataSource(
|
|
|
125
117
|
market="BITVAVO",
|
|
126
118
|
symbol="BTC/EUR",
|
|
127
119
|
timeframe="2h",
|
|
128
|
-
start_date_func=
|
|
120
|
+
start_date_func=lambda : datetime.utcnow() - timedelta(days=17)
|
|
129
121
|
)
|
|
130
122
|
app = create_app({RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()})
|
|
131
123
|
|
|
@@ -25,20 +25,16 @@ It also exposes an REST API that allows you to interact with the algorithm.
|
|
|
25
25
|
```python
|
|
26
26
|
import pathlib
|
|
27
27
|
from datetime import datetime, timedelta
|
|
28
|
-
|
|
29
28
|
from investing_algorithm_framework import create_app, PortfolioConfiguration, \
|
|
30
29
|
RESOURCE_DIRECTORY, TimeUnit, CCXTOHLCVMarketDataSource, Algorithm
|
|
31
30
|
|
|
32
|
-
def start_date_func():
|
|
33
|
-
return datetime.utcnow() - timedelta(days=17)
|
|
34
|
-
|
|
35
31
|
# Define market data sources
|
|
36
32
|
bitvavo_btc_eur_ohlcv_2h = CCXTOHLCVMarketDataSource(
|
|
37
33
|
identifier="BTC",
|
|
38
34
|
market="BITVAVO",
|
|
39
35
|
symbol="BTC/EUR",
|
|
40
36
|
timeframe="2h",
|
|
41
|
-
start_date_func=
|
|
37
|
+
start_date_func=lambda : datetime.utcnow() - timedelta(days=17)
|
|
42
38
|
)
|
|
43
39
|
app = create_app({RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()})
|
|
44
40
|
app.add_portfolio_configuration(
|
|
@@ -46,7 +42,7 @@ app.add_portfolio_configuration(
|
|
|
46
42
|
market="BITVAVO",
|
|
47
43
|
api_key="<your api key>",
|
|
48
44
|
secret_key="<your secret key>",
|
|
49
|
-
trading_symbol="
|
|
45
|
+
trading_symbol="EUR"
|
|
50
46
|
)
|
|
51
47
|
)
|
|
52
48
|
|
|
@@ -75,12 +71,8 @@ but instead of running the algorithm, you can run a backtest.
|
|
|
75
71
|
```python
|
|
76
72
|
import pathlib
|
|
77
73
|
from datetime import datetime, timedelta
|
|
78
|
-
|
|
79
74
|
from investing_algorithm_framework import create_app, RESOURCE_DIRECTORY, \
|
|
80
|
-
TimeUnit, CCXTOHLCVMarketDataSource, Algorithm
|
|
81
|
-
|
|
82
|
-
def start_date_func():
|
|
83
|
-
return datetime.utcnow() - timedelta(days=17)
|
|
75
|
+
TimeUnit, CCXTOHLCVMarketDataSource, Algorithm, pretty_print_backtest
|
|
84
76
|
|
|
85
77
|
# Define market data sources
|
|
86
78
|
bitvavo_btc_eur_ohlcv_2h = CCXTOHLCVMarketDataSource(
|
|
@@ -88,7 +80,7 @@ bitvavo_btc_eur_ohlcv_2h = CCXTOHLCVMarketDataSource(
|
|
|
88
80
|
market="BITVAVO",
|
|
89
81
|
symbol="BTC/EUR",
|
|
90
82
|
timeframe="2h",
|
|
91
|
-
start_date_func=
|
|
83
|
+
start_date_func=lambda : datetime.utcnow() - timedelta(days=17)
|
|
92
84
|
)
|
|
93
85
|
app = create_app({RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()})
|
|
94
86
|
|
|
@@ -50,16 +50,16 @@ class Algorithm:
|
|
|
50
50
|
self.strategy_orchestrator_service.run_pending_jobs()
|
|
51
51
|
|
|
52
52
|
def create_order(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
53
|
+
self,
|
|
54
|
+
target_symbol,
|
|
55
|
+
price,
|
|
56
|
+
order_type,
|
|
57
|
+
order_side,
|
|
58
|
+
amount,
|
|
59
|
+
market=None,
|
|
60
|
+
execute=True,
|
|
61
|
+
validate=True,
|
|
62
|
+
sync=True
|
|
63
63
|
):
|
|
64
64
|
portfolio = self.portfolio_service.find({"market": market})
|
|
65
65
|
order_data = {
|
|
@@ -83,18 +83,18 @@ class Algorithm:
|
|
|
83
83
|
)
|
|
84
84
|
|
|
85
85
|
def create_limit_order(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
86
|
+
self,
|
|
87
|
+
target_symbol,
|
|
88
|
+
price,
|
|
89
|
+
order_side,
|
|
90
|
+
amount=None,
|
|
91
|
+
percentage_of_portfolio=None,
|
|
92
|
+
percentage_of_position=None,
|
|
93
|
+
precision=None,
|
|
94
|
+
market=None,
|
|
95
|
+
execute=True,
|
|
96
|
+
validate=True,
|
|
97
|
+
sync=True
|
|
98
98
|
):
|
|
99
99
|
portfolio = self.portfolio_service.find({"market": market})
|
|
100
100
|
|
|
@@ -148,14 +148,14 @@ class Algorithm:
|
|
|
148
148
|
)
|
|
149
149
|
|
|
150
150
|
def create_market_order(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
151
|
+
self,
|
|
152
|
+
target_symbol,
|
|
153
|
+
order_side,
|
|
154
|
+
amount,
|
|
155
|
+
market=None,
|
|
156
|
+
execute=False,
|
|
157
|
+
validate=False,
|
|
158
|
+
sync=True
|
|
159
159
|
):
|
|
160
160
|
portfolio = self.portfolio_service.find({"market": market})
|
|
161
161
|
order_data = {
|
|
@@ -201,13 +201,13 @@ class Algorithm:
|
|
|
201
201
|
self._running_workers = []
|
|
202
202
|
|
|
203
203
|
def get_order(
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
204
|
+
self,
|
|
205
|
+
reference_id=None,
|
|
206
|
+
market=None,
|
|
207
|
+
target_symbol=None,
|
|
208
|
+
trading_symbol=None,
|
|
209
|
+
order_side=None,
|
|
210
|
+
order_type=None
|
|
211
211
|
) -> Order:
|
|
212
212
|
query_params = {}
|
|
213
213
|
|
|
@@ -236,12 +236,12 @@ class Algorithm:
|
|
|
236
236
|
return self.order_service.find(query_params)
|
|
237
237
|
|
|
238
238
|
def get_orders(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
239
|
+
self,
|
|
240
|
+
target_symbol=None,
|
|
241
|
+
status=None,
|
|
242
|
+
order_type=None,
|
|
243
|
+
order_side=None,
|
|
244
|
+
market=None
|
|
245
245
|
) -> List[Order]:
|
|
246
246
|
|
|
247
247
|
if market is None:
|
|
@@ -326,14 +326,14 @@ class Algorithm:
|
|
|
326
326
|
return None
|
|
327
327
|
|
|
328
328
|
def has_position(
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
329
|
+
self,
|
|
330
|
+
symbol,
|
|
331
|
+
market=None,
|
|
332
|
+
identifier=None,
|
|
333
|
+
amount_gt=0,
|
|
334
|
+
amount_gte=None,
|
|
335
|
+
amount_lt=None,
|
|
336
|
+
amount_lte=None
|
|
337
337
|
):
|
|
338
338
|
return self.position_exists(
|
|
339
339
|
symbol,
|
|
@@ -379,7 +379,7 @@ class Algorithm:
|
|
|
379
379
|
return self.position_service.exists(query_params)
|
|
380
380
|
|
|
381
381
|
def get_position_percentage_of_portfolio(
|
|
382
|
-
|
|
382
|
+
self, symbol, market=None, identifier=None
|
|
383
383
|
) -> float:
|
|
384
384
|
"""
|
|
385
385
|
Returns the percentage of the current total value of the portfolio
|
|
@@ -412,7 +412,7 @@ class Algorithm:
|
|
|
412
412
|
return (position.amount * ticker["bid"] / total) * 100
|
|
413
413
|
|
|
414
414
|
def get_position_percentage_of_portfolio_by_net_size(
|
|
415
|
-
|
|
415
|
+
self, symbol, market=None, identifier=None
|
|
416
416
|
) -> float:
|
|
417
417
|
"""
|
|
418
418
|
Returns the percentage of the portfolio that is allocated to a
|
|
@@ -442,7 +442,6 @@ class Algorithm:
|
|
|
442
442
|
net_size = portfolio.get_net_size()
|
|
443
443
|
return (position.cost / net_size) * 100
|
|
444
444
|
|
|
445
|
-
|
|
446
445
|
def close_position(self, symbol, market=None, identifier=None):
|
|
447
446
|
portfolio = self.portfolio_service.find(
|
|
448
447
|
{"market": market, "identifier": identifier}
|
|
@@ -459,9 +458,9 @@ class Algorithm:
|
|
|
459
458
|
return
|
|
460
459
|
|
|
461
460
|
for order in self.order_service \
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
461
|
+
.get_all({
|
|
462
|
+
"position": position.id, "status": OrderStatus.OPEN.value
|
|
463
|
+
}):
|
|
465
464
|
self.market_service.cancel_order(order.id)
|
|
466
465
|
|
|
467
466
|
ticker = self.market_service.get_ticker(
|
|
@@ -704,6 +703,27 @@ class Algorithm:
|
|
|
704
703
|
"order_side": OrderSide.BUY.value,
|
|
705
704
|
"target_symbol": target_symbol
|
|
706
705
|
})
|
|
706
|
+
sell_orders = self.order_service.get_all({
|
|
707
|
+
"status": OrderStatus.OPEN.value,
|
|
708
|
+
"order_side": OrderSide.SELL.value,
|
|
709
|
+
"target_symbol": target_symbol
|
|
710
|
+
})
|
|
711
|
+
sell_amount = sum([order.get_amount() for order in sell_orders])
|
|
712
|
+
|
|
713
|
+
# Subtract the amount of the open sell orders
|
|
714
|
+
# from the amount of the buy orders
|
|
715
|
+
while sell_amount > 0 and len(buy_orders) > 0:
|
|
716
|
+
first_order = buy_orders[0]
|
|
717
|
+
|
|
718
|
+
if first_order.get_available_amount() > sell_amount:
|
|
719
|
+
first_order.set_available_amount(
|
|
720
|
+
first_order.get_available_amount() - sell_amount
|
|
721
|
+
)
|
|
722
|
+
sell_amount = 0
|
|
723
|
+
else:
|
|
724
|
+
sell_amount = sell_amount - first_order.get_available_amount()
|
|
725
|
+
buy_orders.pop(0)
|
|
726
|
+
|
|
707
727
|
symbols = [order.get_symbol() for order in buy_orders]
|
|
708
728
|
symbols = list(set(symbols))
|
|
709
729
|
tickers = {}
|
|
@@ -737,13 +757,24 @@ class Algorithm:
|
|
|
737
757
|
"Buy order belonging to the trade has no amount."
|
|
738
758
|
)
|
|
739
759
|
|
|
760
|
+
position = self.get_position(order.get_target_symbol())
|
|
761
|
+
amount = order.get_amount()
|
|
762
|
+
if position.get_amount() < amount:
|
|
763
|
+
logger.warning(
|
|
764
|
+
f"Order amount {amount} is larger then amount "
|
|
765
|
+
f"of available {position.symbol} "
|
|
766
|
+
f"position: {position.get_amount()}, "
|
|
767
|
+
f"changing order amount to size of position"
|
|
768
|
+
)
|
|
769
|
+
amount = position.get_amount()
|
|
770
|
+
|
|
740
771
|
ticker = self.market_service.get_ticker(
|
|
741
772
|
symbol=f"{order.target_symbol.upper()}"
|
|
742
773
|
f"/{order.trading_symbol.upper()}"
|
|
743
774
|
)
|
|
744
775
|
self.create_limit_order(
|
|
745
776
|
target_symbol=order.target_symbol,
|
|
746
|
-
amount=
|
|
777
|
+
amount=amount,
|
|
747
778
|
order_side=OrderSide.SELL.value,
|
|
748
779
|
price=ticker["bid"],
|
|
749
780
|
)
|
|
@@ -79,6 +79,7 @@ class Order(BaseModel):
|
|
|
79
79
|
self.stop_loss_percentage = stop_loss_percentage
|
|
80
80
|
self.trailing_stop_loss = trailing_stop_loss
|
|
81
81
|
self.trailing_stop_loss_percentage = trailing_stop_loss_percentage
|
|
82
|
+
self._available_amount = self.filled
|
|
82
83
|
|
|
83
84
|
def get_external_id(self):
|
|
84
85
|
return self.external_id
|
|
@@ -205,17 +206,23 @@ class Order(BaseModel):
|
|
|
205
206
|
def get_symbol(self):
|
|
206
207
|
return self.get_target_symbol() + "/" + self.get_trading_symbol()
|
|
207
208
|
|
|
208
|
-
def
|
|
209
|
-
return self.stop_loss
|
|
209
|
+
def get_available_amount(self):
|
|
210
210
|
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
if self._available_amount is None:
|
|
212
|
+
return self.get_filled()
|
|
213
213
|
|
|
214
|
-
|
|
215
|
-
return self.trailing_stop_loss
|
|
214
|
+
return self._available_amount
|
|
216
215
|
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
@property
|
|
217
|
+
def available_amount(self):
|
|
218
|
+
return self.get_available_amount()
|
|
219
|
+
|
|
220
|
+
def set_available_amount(self, available_amount):
|
|
221
|
+
self._available_amount = available_amount
|
|
222
|
+
|
|
223
|
+
@available_amount.setter
|
|
224
|
+
def available_amount(self, available_amount):
|
|
225
|
+
self.set_available_amount(available_amount)
|
|
219
226
|
|
|
220
227
|
def to_dict(self):
|
|
221
228
|
return {
|
|
@@ -287,4 +294,4 @@ class Order(BaseModel):
|
|
|
287
294
|
filled=self.get_filled(),
|
|
288
295
|
remaining=self.get_remaining(),
|
|
289
296
|
cost=self.get_cost(),
|
|
290
|
-
)
|
|
297
|
+
)
|
|
@@ -172,7 +172,7 @@ class CCXTTickerBacktestMarketDataSource(
|
|
|
172
172
|
backtest_data_index_date = None
|
|
173
173
|
backtest_data_start_date = None
|
|
174
174
|
backtest_data_end_date = None
|
|
175
|
-
total_minutes_timeframe =
|
|
175
|
+
total_minutes_timeframe = 15
|
|
176
176
|
|
|
177
177
|
def __init__(
|
|
178
178
|
self,
|
|
@@ -221,7 +221,7 @@ class CCXTTickerBacktestMarketDataSource(
|
|
|
221
221
|
market_service.market = self.market
|
|
222
222
|
ohlcv = market_service.get_ohlcv(
|
|
223
223
|
symbol=self.symbol,
|
|
224
|
-
time_frame="
|
|
224
|
+
time_frame="15m",
|
|
225
225
|
from_timestamp=backtest_data_start_date,
|
|
226
226
|
to_timestamp=backtest_end_date
|
|
227
227
|
)
|
|
@@ -309,14 +309,16 @@ class CCXTTickerBacktestMarketDataSource(
|
|
|
309
309
|
if difference_in_minutes <= 240:
|
|
310
310
|
return {
|
|
311
311
|
"symbol": self.symbol,
|
|
312
|
-
"bid": float(previous_row[
|
|
313
|
-
"ask": float(previous_row[
|
|
312
|
+
"bid": float(previous_row[3]) + float(previous_row[2]) / 2,
|
|
313
|
+
"ask": float(previous_row[3]) + float(previous_row[2]) / 2,
|
|
314
314
|
"datetime": previous_row[0],
|
|
315
315
|
}
|
|
316
316
|
|
|
317
317
|
raise OperationalException(
|
|
318
|
-
f"Could not find ticker data for date "
|
|
319
|
-
f"{backtest_index_date}"
|
|
318
|
+
f"Could not find {self.symbol} ticker data for date "
|
|
319
|
+
f"{backtest_index_date}. Please make sure that the selected "
|
|
320
|
+
f"broker or exchange {self.market} has ticker data"
|
|
321
|
+
f" available for symbol {self.symbol}"
|
|
320
322
|
)
|
|
321
323
|
|
|
322
324
|
def to_backtest_market_data_source(self) -> BacktestMarketDataSource:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: investing-algorithm-framework
|
|
3
|
-
Version: 1.7
|
|
3
|
+
Version: 1.7.2
|
|
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
|
|
@@ -62,20 +62,16 @@ It also exposes an REST API that allows you to interact with the algorithm.
|
|
|
62
62
|
```python
|
|
63
63
|
import pathlib
|
|
64
64
|
from datetime import datetime, timedelta
|
|
65
|
-
|
|
66
65
|
from investing_algorithm_framework import create_app, PortfolioConfiguration, \
|
|
67
66
|
RESOURCE_DIRECTORY, TimeUnit, CCXTOHLCVMarketDataSource, Algorithm
|
|
68
67
|
|
|
69
|
-
def start_date_func():
|
|
70
|
-
return datetime.utcnow() - timedelta(days=17)
|
|
71
|
-
|
|
72
68
|
# Define market data sources
|
|
73
69
|
bitvavo_btc_eur_ohlcv_2h = CCXTOHLCVMarketDataSource(
|
|
74
70
|
identifier="BTC",
|
|
75
71
|
market="BITVAVO",
|
|
76
72
|
symbol="BTC/EUR",
|
|
77
73
|
timeframe="2h",
|
|
78
|
-
start_date_func=
|
|
74
|
+
start_date_func=lambda : datetime.utcnow() - timedelta(days=17)
|
|
79
75
|
)
|
|
80
76
|
app = create_app({RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()})
|
|
81
77
|
app.add_portfolio_configuration(
|
|
@@ -83,7 +79,7 @@ app.add_portfolio_configuration(
|
|
|
83
79
|
market="BITVAVO",
|
|
84
80
|
api_key="<your api key>",
|
|
85
81
|
secret_key="<your secret key>",
|
|
86
|
-
trading_symbol="
|
|
82
|
+
trading_symbol="EUR"
|
|
87
83
|
)
|
|
88
84
|
)
|
|
89
85
|
|
|
@@ -112,12 +108,8 @@ but instead of running the algorithm, you can run a backtest.
|
|
|
112
108
|
```python
|
|
113
109
|
import pathlib
|
|
114
110
|
from datetime import datetime, timedelta
|
|
115
|
-
|
|
116
111
|
from investing_algorithm_framework import create_app, RESOURCE_DIRECTORY, \
|
|
117
|
-
TimeUnit, CCXTOHLCVMarketDataSource, Algorithm
|
|
118
|
-
|
|
119
|
-
def start_date_func():
|
|
120
|
-
return datetime.utcnow() - timedelta(days=17)
|
|
112
|
+
TimeUnit, CCXTOHLCVMarketDataSource, Algorithm, pretty_print_backtest
|
|
121
113
|
|
|
122
114
|
# Define market data sources
|
|
123
115
|
bitvavo_btc_eur_ohlcv_2h = CCXTOHLCVMarketDataSource(
|
|
@@ -125,7 +117,7 @@ bitvavo_btc_eur_ohlcv_2h = CCXTOHLCVMarketDataSource(
|
|
|
125
117
|
market="BITVAVO",
|
|
126
118
|
symbol="BTC/EUR",
|
|
127
119
|
timeframe="2h",
|
|
128
|
-
start_date_func=
|
|
120
|
+
start_date_func=lambda : datetime.utcnow() - timedelta(days=17)
|
|
129
121
|
)
|
|
130
122
|
app = create_app({RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()})
|
|
131
123
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{investing_algorithm_framework-1.7 → investing_algorithm_framework-1.7.2}/tests/test_create_app.py
RENAMED
|
File without changes
|