Skip to content

Commit f191bbd

Browse files
committed
Refactor to new data providers
1 parent dd9773f commit f191bbd

File tree

14 files changed

+1580
-819
lines changed

14 files changed

+1580
-819
lines changed

examples/bitvavo_trading_bot.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import logging.config
33

44
from investing_algorithm_framework import TimeUnit, TradingStrategy, \
5-
CCXTOHLCVMarketDataSource, CCXTTickerMarketDataSource, \
6-
create_app, DEFAULT_LOGGING_CONFIG, Context
5+
create_app, DEFAULT_LOGGING_CONFIG, Context, DataSource
76

87
"""
98
Bitvavo trading bot example with market data sources of bitvavo.
@@ -19,24 +18,14 @@
1918
# Load the environment variables from the .env file
2019
load_dotenv()
2120

22-
# Define your market data sources for coinbase
23-
bitvavo_btc_eur_ohlcv_2h = CCXTOHLCVMarketDataSource(
24-
identifier="BTC/EUR-ohlcv",
25-
market="bitvavo",
26-
symbol="BTC/EUR",
27-
time_frame="2h",
28-
window_size=200
29-
)
30-
bitvavo_btc_eur_ticker = CCXTTickerMarketDataSource(
31-
identifier="BTC/EUR-ticker",
32-
market="bitvavo",
33-
symbol="BTC/EUR",
34-
)
35-
21+
# Define your bitvavo trading strategy and register the data sources
3622
class BitvavoTradingStrategy(TradingStrategy):
3723
time_unit = TimeUnit.SECOND
3824
interval = 10
39-
market_data_sources = [bitvavo_btc_eur_ohlcv_2h, bitvavo_btc_eur_ticker]
25+
data_sources = [
26+
DataSource(data_type="OHLCV", market="bitvavo", symbol="BTC/EUR", window_size=200, time_frame="2h", indentifier="BTC/EUR-ohlcv"),
27+
DataSource(data_type="Ticker", market="bitvavo", symbol="BTC/EUR", indentifier="BTC/EUR-ticker")
28+
]
4029

4130
def run_strategy(self, context: Context, market_data):
4231
print(market_data["BTC/EUR-ohlcv"])
@@ -45,6 +34,9 @@ def run_strategy(self, context: Context, market_data):
4534
# Create an app and add the market data sources and market credentials to it
4635
app = create_app()
4736
app.add_strategy(BitvavoTradingStrategy)
37+
38+
# Market credentials for bitvavo for both the portfolio connection and data sources will
39+
# be read from .env file, when not registering a market credential object in the app.
4840
app.add_market(market="bitvavo", trading_symbol="EUR", initial_balance=400)
4941

5042
if __name__ == "__main__":

examples/coinbase_trading_bot.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
11
from dotenv import load_dotenv
22
import logging.config
33
from investing_algorithm_framework import TimeUnit, \
4-
CCXTOHLCVMarketDataSource, CCXTTickerMarketDataSource, TradingStrategy, \
5-
create_app, DEFAULT_LOGGING_CONFIG, Context
4+
DataSource, TradingStrategy, create_app, DEFAULT_LOGGING_CONFIG, Context
65
"""
7-
Coinbase market data sources example. Coinbase requires you to have an API key
6+
Coinbase trading bot example. Coinbase requires you to have an API key
87
and secret key to access their market data. You can create them here:
98
https://www.coinbase.com/settings/api
10-
11-
You need to add a market credential to the app, and then add market
12-
data sources to the app. You can then use the market data
13-
sources in your trading strategy.
149
"""
1510

1611
logging.config.dictConfig(DEFAULT_LOGGING_CONFIG)
1712

1813
# Load the environment variables from the .env file
1914
load_dotenv()
2015

21-
# Define your market data sources for coinbase
22-
coinbase_btc_eur_ohlcv_2h = CCXTOHLCVMarketDataSource(
23-
identifier="BTC/EUR-ohlcv",
24-
market="coinbase",
25-
symbol="BTC/EUR",
26-
time_frame="2h",
27-
window_size=200
28-
)
29-
coinbase_btc_eur_ticker = CCXTTickerMarketDataSource(
30-
identifier="BTC/EUR-ticker",
31-
market="coinbase",
32-
symbol="BTC/EUR",
33-
)
34-
35-
16+
# Define your coinbase trading strategy and register the data sources
3617
class CoinbaseTradingStrategy(TradingStrategy):
3718
time_unit = TimeUnit.SECOND
3819
interval = 10
39-
market_data_sources = [coinbase_btc_eur_ohlcv_2h, coinbase_btc_eur_ticker]
20+
data_sources = [
21+
DataSource(data_type="OHLCV", market="coinbase", symbol="BTC/EUR", window_size=200, time_frame="2h", indentifier="BTC/EUR-ohlcv"),
22+
DataSource(data_type="Ticker", market="coinbase", symbol="BTC/EUR", indentifier="BTC/EUR-ticker")
23+
]
4024

4125
def apply_strategy(self, context: Context, market_data):
4226
print(market_data["BTC/EUR-ohlcv"])
@@ -45,6 +29,9 @@ def apply_strategy(self, context: Context, market_data):
4529
# Create an app and configure it with coinbase
4630
app = create_app()
4731
app.add_strategy(CoinbaseTradingStrategy)
32+
33+
# Market credentials for coinbase for both the portfolio connection and data sources will
34+
# be read from .env file, when not registering a market credential object in the app.
4835
app.add_market(market="coinbase", trading_symbol="EUR", initial_balance=400)
4936

5037
if __name__ == "__main__":

investing_algorithm_framework/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
CCXTTickerMarketDataSource, CSVOHLCVMarketDataSource, \
2222
CSVTickerMarketDataSource, AzureBlobStorageStateHandler, \
2323
PandasOHLCVBacktestMarketDataSource, PandasOHLCVMarketDataSource, \
24-
AWSS3StorageStateHandler
24+
AWSS3StorageStateHandler, CSVOHLCVDataProvider, CCXTOHLCVDataProvider
2525
from .create_app import create_app
2626
from .download_data import download
2727

@@ -92,5 +92,7 @@
9292
"AWS_S3_STATE_BUCKET_NAME",
9393
"AWS_LAMBDA_LOGGING_CONFIG",
9494
'select_backtest_date_ranges',
95-
'DataType'
95+
'DataType',
96+
'CSVOHLCVDataProvider',
97+
"CCXTOHLCVDataProvider"
9698
]

investing_algorithm_framework/app/strategy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from investing_algorithm_framework.domain import OperationalException, Position
66
from investing_algorithm_framework.domain import \
77
TimeUnit, StrategyProfile, Trade, ENVIRONMENT, Environment, \
8-
BACKTESTING_INDEX_DATETIME
8+
BACKTESTING_INDEX_DATETIME, DataSource
99
from .context import Context
1010

1111

@@ -23,17 +23,17 @@ class TradingStrategy:
2323
worker_id (optional): str - the id of the worker
2424
strategy_id (optional): str - the id of the strategy
2525
decorated (optional): function - the decorated function
26-
data_sources (List[DataSource] optional):the list of data
26+
data_sources (List[DataSource] optional): the list of data
2727
sources to use for the strategy. The data sources will be used
28-
to indetify data providers that will be called to gather data
28+
to indentify data providers that will be called to gather data
2929
and pass to the strategy before its run.
3030
"""
3131
time_unit: str = None
3232
interval: int = None
3333
worker_id: str = None
3434
strategy_id: str = None
3535
decorated = None
36-
data_sources = None
36+
data_sources: List[DataSource] = None
3737
traces = None
3838
context: Context = None
3939

0 commit comments

Comments
 (0)