Remove combined load-method since it's confusing

This commit is contained in:
Matthias 2019-06-22 16:20:41 +02:00
parent 3e61ada34a
commit 559d5ebd1d
3 changed files with 17 additions and 40 deletions

View File

@ -58,7 +58,7 @@ Timerange doesn't work with live data.
To plot trades stored in a database use `--db-url` argument: To plot trades stored in a database use `--db-url` argument:
``` bash ``` 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 <filename>` To plot trades from a backtesting result, use `--export-filename <filename>`

View File

@ -82,36 +82,21 @@ def load_trades_from_db(db_url: str) -> pd.DataFrame:
trades: pd.DataFrame = pd.DataFrame([], columns=BT_DATA_COLUMNS) trades: pd.DataFrame = pd.DataFrame([], columns=BT_DATA_COLUMNS)
persistence.init(db_url, clean_open_orders=False) persistence.init(db_url, clean_open_orders=False)
columns = ["pair", "profit", "open_time", "close_time", 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(): trades = pd.DataFrame([(t.pair, t.calc_profit(),
logger.info("date: {}".format(x.open_date)) t.open_date.replace(tzinfo=pytz.UTC),
t.close_date.replace(tzinfo=pytz.UTC) if t.close_date else None,
trades = pd.DataFrame([(t.pair, t.calc_profit(), t.open_rate, t.close_rate,
t.open_date.replace(tzinfo=pytz.UTC), t.close_date.timestamp() - t.open_date.timestamp()
t.close_date.replace(tzinfo=pytz.UTC) if t.close_date else None, if t.close_date else None,
t.open_rate, t.close_rate, t.sell_reason,
t.close_date.timestamp() - t.open_date.timestamp() t.max_rate,
if t.close_date else None) t.min_rate,
for t in Trade.query.all()], )
columns=columns) 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)
return trades return trades

View File

@ -7,7 +7,7 @@ from pandas import DataFrame, to_datetime
from freqtrade.arguments import TimeRange from freqtrade.arguments import TimeRange
from freqtrade.data.btanalysis import (BT_DATA_COLUMNS, from freqtrade.data.btanalysis import (BT_DATA_COLUMNS,
extract_trades_of_period, 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.data.history import load_pair_history, make_testdata_path
from freqtrade.tests.test_persistence import create_mock_trades from freqtrade.tests.test_persistence import create_mock_trades
@ -28,14 +28,6 @@ def test_load_backtest_data():
load_backtest_data(str("filename") + "nofile") 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") @pytest.mark.usefixtures("init_persistence")
def test_load_trades_db(default_conf, fee, mocker): 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 # remove init so it does not init again
init_mock = mocker.patch('freqtrade.persistence.init', MagicMock()) 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 init_mock.call_count == 1
assert len(trades) == 3 assert len(trades) == 3
assert isinstance(trades, DataFrame) assert isinstance(trades, DataFrame)