From 559d5ebd1deae0f4cf521d2d88077e0dbdb8c552 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 22 Jun 2019 16:20:41 +0200 Subject: [PATCH] Remove combined load-method since it's confusing --- docs/plotting.md | 2 +- freqtrade/data/btanalysis.py | 43 ++++++++----------------- freqtrade/tests/data/test_btanalysis.py | 12 ++----- 3 files changed, 17 insertions(+), 40 deletions(-) diff --git a/docs/plotting.md b/docs/plotting.md index 6dc3d13b1..b8e041d61 100644 --- a/docs/plotting.md +++ b/docs/plotting.md @@ -58,7 +58,7 @@ Timerange doesn't work with live data. To plot trades stored in a database use `--db-url` argument: ``` bash -python3 scripts/plot_dataframe.py --db-url sqlite:///tradesv3.dry_run.sqlite -p BTC/ETH +python3 scripts/plot_dataframe.py --db-url sqlite:///tradesv3.dry_run.sqlite -p BTC/ETH --trade-source DB ``` To plot trades from a backtesting result, use `--export-filename ` diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py index 5efb10433..9d6d90cf3 100644 --- a/freqtrade/data/btanalysis.py +++ b/freqtrade/data/btanalysis.py @@ -82,36 +82,21 @@ def load_trades_from_db(db_url: str) -> pd.DataFrame: trades: pd.DataFrame = pd.DataFrame([], columns=BT_DATA_COLUMNS) persistence.init(db_url, clean_open_orders=False) columns = ["pair", "profit", "open_time", "close_time", - "open_rate", "close_rate", "duration"] + "open_rate", "close_rate", "duration", "sell_reason", + "max_rate", "min_rate"] - for x in Trade.query.all(): - logger.info("date: {}".format(x.open_date)) - - trades = pd.DataFrame([(t.pair, t.calc_profit(), - t.open_date.replace(tzinfo=pytz.UTC), - t.close_date.replace(tzinfo=pytz.UTC) if t.close_date else None, - t.open_rate, t.close_rate, - t.close_date.timestamp() - t.open_date.timestamp() - if t.close_date else None) - for t in Trade.query.all()], - columns=columns) - - return trades - - -def load_trades(exportfilename: str = None, db_url: str = None) -> pd.DataFrame: - """ - Load trades, either from a DB (using dburl) or via a backtest export file. - :param exportfilename: Path to a file exported from backtesting - :param db_url: Sqlite url (default format sqlite:///tradesv3.dry-run.sqlite) - :returns: Dataframe containing Trades - """ - - trades: pd.DataFrame = pd.DataFrame([], columns=BT_DATA_COLUMNS) - if exportfilename: - trades = load_backtest_data(Path(exportfilename)) - elif db_url: - trades = load_trades_from_db(db_url) + trades = pd.DataFrame([(t.pair, t.calc_profit(), + t.open_date.replace(tzinfo=pytz.UTC), + t.close_date.replace(tzinfo=pytz.UTC) if t.close_date else None, + t.open_rate, t.close_rate, + t.close_date.timestamp() - t.open_date.timestamp() + if t.close_date else None, + t.sell_reason, + t.max_rate, + t.min_rate, + ) + for t in Trade.query.all()], + columns=columns) return trades diff --git a/freqtrade/tests/data/test_btanalysis.py b/freqtrade/tests/data/test_btanalysis.py index 6fa529394..1cb48393d 100644 --- a/freqtrade/tests/data/test_btanalysis.py +++ b/freqtrade/tests/data/test_btanalysis.py @@ -7,7 +7,7 @@ from pandas import DataFrame, to_datetime from freqtrade.arguments import TimeRange from freqtrade.data.btanalysis import (BT_DATA_COLUMNS, extract_trades_of_period, - load_backtest_data, load_trades) + load_backtest_data, load_trades_from_db) from freqtrade.data.history import load_pair_history, make_testdata_path from freqtrade.tests.test_persistence import create_mock_trades @@ -28,14 +28,6 @@ def test_load_backtest_data(): load_backtest_data(str("filename") + "nofile") -def test_load_trades_file(default_conf, fee, mocker): - # Real testing of load_backtest_data is done in test_load_backtest_data - lbt = mocker.patch("freqtrade.data.btanalysis.load_backtest_data", MagicMock()) - filename = make_testdata_path(None) / "backtest-result_test.json" - load_trades(db_url=None, exportfilename=filename) - assert lbt.call_count == 1 - - @pytest.mark.usefixtures("init_persistence") def test_load_trades_db(default_conf, fee, mocker): @@ -43,7 +35,7 @@ def test_load_trades_db(default_conf, fee, mocker): # remove init so it does not init again init_mock = mocker.patch('freqtrade.persistence.init', MagicMock()) - trades = load_trades(db_url=default_conf['db_url'], exportfilename=None) + trades = load_trades_from_db(db_url=default_conf['db_url']) assert init_mock.call_count == 1 assert len(trades) == 3 assert isinstance(trades, DataFrame)