Skip to content

Commit 4a1c579

Browse files
committed
Add symbols specification
1 parent 12b2d18 commit 4a1c579

File tree

14 files changed

+214
-68
lines changed

14 files changed

+214
-68
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,6 @@ lib/
145145
bumpversion.egg-info/
146146
*.sqlite3
147147

148-
*/backtest_data/
149-
*/backtest_reports/
148+
**/backtest_data/*
149+
*/backtest_reports/
150+
**/backtest_reports/*

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ It also exposes an REST API that allows you to interact with the algorithm.
3838
import pathlib
3939
from investing_algorithm_framework import create_app, PortfolioConfiguration, \
4040
RESOURCE_DIRECTORY, TimeUnit, CCXTOHLCVMarketDataSource, Algorithm, \
41-
CCXTTickerMarketDataSource, MarketCredential
41+
CCXTTickerMarketDataSource, MarketCredential, SYMBOLS
42+
43+
# Define resource directory and the symbols you want to trade
44+
config = {
45+
RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()
46+
SYMBOLS: ["BTC/EUR"]
47+
}
4248

4349
# Define market data sources
4450
bitvavo_btc_eur_ohlcv_2h = CCXTOHLCVMarketDataSource(
@@ -54,7 +60,7 @@ bitvavo_btc_eur_ticker = CCXTTickerMarketDataSource(
5460
market="BITVAVO",
5561
symbol="BTC/EUR",
5662
)
57-
app = create_app({RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()})
63+
app = create_app(config=config)
5864
algorithm = Algorithm()
5965

6066
app.add_market_data_source(bitvavo_btc_eur_ohlcv_2h)

examples/backtest/app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
app = create_app(
66
config={RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()}
77
)
8+
9+
10+
if __name__ == "__main__":
11+
app.run()

examples/bitvavo_trading_bot/bitvavo.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import os
12
from investing_algorithm_framework import MarketCredential, TimeUnit, \
23
CCXTOHLCVMarketDataSource, CCXTTickerMarketDataSource, TradingStrategy, \
3-
create_app, PortfolioConfiguration, Algorithm
4+
create_app, PortfolioConfiguration, Algorithm, SYMBOLS, RESOURCE_DIRECTORY
45

56
"""
67
Bitvavo trading bot example with market data sources of bitvavo.
@@ -45,12 +46,18 @@ def apply_strategy(self, algorithm, market_data):
4546
print(market_data["BTC/EUR-ohlcv"])
4647
print(market_data["BTC/EUR-ticker"])
4748

49+
50+
config = {
51+
SYMBOLS: ["BTC/EUR"],
52+
RESOURCE_DIRECTORY: os.path.join(os.path.dirname(__file__), "resources")
53+
}
54+
4855
# Create an algorithm and link your trading strategy to it
4956
algorithm = Algorithm()
5057
algorithm.add_strategy(BitvavoTradingStrategy)
5158

5259
# Create an app and add the market data sources and market credentials to it
53-
app = create_app()
60+
app = create_app(config=config)
5461
app.add_market_credential(bitvavo_market_credential)
5562
app.add_market_data_source(bitvavo_btc_eur_ohlcv_2h)
5663
app.add_market_data_source(bitvavo_btc_eur_ticker)

examples/coinbase_trading_bot/coinbase.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import os
12
from investing_algorithm_framework import MarketCredential, TimeUnit, \
23
CCXTOHLCVMarketDataSource, CCXTTickerMarketDataSource, TradingStrategy, \
3-
create_app, PortfolioConfiguration, Algorithm
4+
create_app, PortfolioConfiguration, Algorithm, SYMBOLS, RESOURCE_DIRECTORY
45

56
"""
67
Coinbase market data sources example. Coinbase requires you to have an API key
@@ -42,11 +43,15 @@ class CoinBaseTradingStrategy(TradingStrategy):
4243
def apply_strategy(self, algorithm, market_data):
4344
pass
4445

46+
config = {
47+
SYMBOLS: ["BTC/EUR"],
48+
RESOURCE_DIRECTORY: os.path.join(os.path.dirname(__file__), "resources")
49+
}
4550

4651
algorithm = Algorithm()
4752
algorithm.add_strategy(CoinBaseTradingStrategy)
4853

49-
app = create_app()
54+
app = create_app(config=config)
5055
app.add_algorithm(algorithm)
5156
app.add_market_credential(coinbase_market_credential)
5257
app.add_market_data_source(coinbase_btc_eur_ohlcv_2h)
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import pathlib
22

3-
from investing_algorithm_framework import create_app, RESOURCE_DIRECTORY
3+
from investing_algorithm_framework import create_app, RESOURCE_DIRECTORY, \
4+
SYMBOLS
45

5-
app = create_app(
6-
config={RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()}
7-
)
6+
config = {
7+
SYMBOLS: ["BTC/EUR"],
8+
RESOURCE_DIRECTORY: pathlib.Path(__file__).parent.resolve()
9+
}
10+
app = create_app(config=config)
811

investing_algorithm_framework/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
OrderStatus, OrderSide, Config, TimeUnit, TimeInterval, Order, Portfolio, \
66
Position, TimeFrame, BACKTESTING_INDEX_DATETIME, MarketCredential, \
77
PortfolioConfiguration, RESOURCE_DIRECTORY, pretty_print_backtest, \
8-
Trade, OHLCVMarketDataSource, OrderBookMarketDataSource, \
8+
Trade, OHLCVMarketDataSource, OrderBookMarketDataSource, SYMBOLS, \
99
TickerMarketDataSource, MarketService, BacktestReportsEvaluation, \
1010
pretty_print_backtest_reports_evaluation, load_backtest_reports
1111
from investing_algorithm_framework.app import TradingStrategy, \
@@ -55,4 +55,5 @@
5555
"pretty_print_backtest_reports_evaluation",
5656
"BacktestReportsEvaluation",
5757
"load_backtest_reports",
58+
"SYMBOLS"
5859
]

investing_algorithm_framework/app/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def _initialize_app_for_backtest(
248248
# Override the portfolio service with the backtest portfolio service
249249
self.container.portfolio_service.override(
250250
BacktestPortfolioService(
251+
configuration_service=self.container.configuration_service(),
251252
market_credential_service=self.container
252253
.market_credential_service(),
253254
market_service=self.container.market_service(),

investing_algorithm_framework/dependency_container.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class DependencyContainer(containers.DeclarativeContainer):
8585
)
8686
portfolio_service = providers.Factory(
8787
PortfolioService,
88+
configuration_service=configuration_service,
8889
market_credential_service=market_credential_service,
8990
market_service=market_service,
9091
position_repository=position_repository,

investing_algorithm_framework/domain/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
DATETIME_FORMAT, DATETIME_FORMAT_BACKTESTING, BACKTESTING_FLAG, \
1414
BACKTESTING_INDEX_DATETIME, BACKTESTING_START_DATE, CCXT_DATETIME_FORMAT, \
1515
BACKTEST_DATA_DIRECTORY_NAME, TICKER_DATA_TYPE, OHLCV_DATA_TYPE, \
16-
CURRENT_UTC_DATETIME, BACKTESTING_END_DATE, \
16+
CURRENT_UTC_DATETIME, BACKTESTING_END_DATE, SYMBOLS, \
1717
CCXT_DATETIME_FORMAT_WITH_TIMEZONE, \
1818
BACKTESTING_PENDING_ORDER_CHECK_INTERVAL
1919
from .singleton import Singleton
@@ -105,4 +105,5 @@
105105
"BacktestReportsEvaluation",
106106
"load_csv_into_dict",
107107
"load_backtest_reports",
108+
"SYMBOLS"
108109
]

0 commit comments

Comments
 (0)