From 936aa9bc142b918859dd6243bae527e3e3d806b9 Mon Sep 17 00:00:00 2001 From: marcvanduyn Date: Mon, 1 Jul 2024 22:28:55 +0200 Subject: [PATCH] Refactor data sources --- .../algorithm/strategy.py | 11 +++++++---- .../backtesting.py | 9 ++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/examples/crossover_moving_average_trading_bot/algorithm/strategy.py b/examples/crossover_moving_average_trading_bot/algorithm/strategy.py index a36d23c0..df818884 100644 --- a/examples/crossover_moving_average_trading_bot/algorithm/strategy.py +++ b/examples/crossover_moving_average_trading_bot/algorithm/strategy.py @@ -2,6 +2,9 @@ from investing_algorithm_framework import TimeUnit, TradingStrategy, \ Algorithm, OrderSide +from .data_sources import bitvavo_btc_eur_ohlcv_2h, bitvavo_btc_eur_ticker, \ + bitvavo_dot_eur_ticker, bitvavo_dot_eur_ohlcv_2h + """ This strategy is based on the golden cross strategy. It will buy when the @@ -49,10 +52,10 @@ class CrossOverStrategy(TradingStrategy): time_unit = TimeUnit.HOUR interval = 2 market_data_sources = [ - "BTC/EUR-ohlcv", - "DOT/EUR-ohlcv", - "BTC/EUR-ticker", - "DOT/EUR-ticker" + bitvavo_dot_eur_ticker, + bitvavo_dot_eur_ohlcv_2h, + bitvavo_btc_eur_ticker, + bitvavo_btc_eur_ohlcv_2h ] symbols = ["BTC/EUR", "DOT/EUR"] diff --git a/examples/crossover_moving_average_trading_bot/backtesting.py b/examples/crossover_moving_average_trading_bot/backtesting.py index 18f668f4..9e34b6ce 100644 --- a/examples/crossover_moving_average_trading_bot/backtesting.py +++ b/examples/crossover_moving_average_trading_bot/backtesting.py @@ -5,7 +5,7 @@ bitvavo_dot_eur_ohlcv_2h, bitvavo_dot_eur_ticker, bitvavo_btc_eur_ticker from app import app from investing_algorithm_framework import PortfolioConfiguration, \ - pretty_print_backtest + pretty_print_backtest, BacktestDateRange app.add_algorithm(algorithm) app.add_market_data_source(bitvavo_btc_eur_ohlcv_2h) @@ -26,10 +26,13 @@ if __name__ == "__main__": end_date = datetime(2023, 12, 2) start_date = end_date - timedelta(days=100) + date_range = BacktestDateRange( + start_date=start_date, + end_date=end_date + ) backtest_report = app.run_backtest( algorithm=algorithm, - start_date=start_date, - end_date=end_date, + backtest_date_range=date_range, pending_order_check_interval="2h", ) pretty_print_backtest(backtest_report)