From c4e30862eeda84a1aa7f4e587c6851bf05905b4b Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 3 Aug 2019 19:55:54 +0200 Subject: [PATCH 1/2] load_trades_db should give as many columns as possible --- freqtrade/data/btanalysis.py | 21 ++++++++++++++++----- freqtrade/tests/data/test_btanalysis.py | 5 +++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py index 5865d56a7..6568fe31e 100644 --- a/freqtrade/data/btanalysis.py +++ b/freqtrade/data/btanalysis.py @@ -81,19 +81,30 @@ 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", "sell_reason", - "max_rate", "min_rate"] - trades = pd.DataFrame([(t.pair, t.calc_profit(), + columns = ["pair", "open_time", "close_time", "profit", "profitperc", + "open_rate", "close_rate", "amount", "duration", "sell_reason", + "fee_open", "fee_close", "open_rate_requested", "close_rate_requested", + "stake_amount", "max_rate", "min_rate", "id", "exchange", + "stop_loss", "initial_stop_loss", "strategy", "ticker_interval"] + + trades = pd.DataFrame([(t.pair, 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.calc_profit(), t.calc_profit_percent(), + t.open_rate, t.close_rate, t.amount, t.close_date.timestamp() - t.open_date.timestamp() if t.close_date else None, t.sell_reason, + t.fee_open, t.fee_close, + t.open_rate_requested, + t.close_rate_requested, + t.stake_amount, t.max_rate, t.min_rate, + t.id, t.exchange, + t.stop_loss, t.initial_stop_loss, + t.strategy, t.ticker_interval ) for t in Trade.query.all()], columns=columns) diff --git a/freqtrade/tests/data/test_btanalysis.py b/freqtrade/tests/data/test_btanalysis.py index e80840009..bad8db66f 100644 --- a/freqtrade/tests/data/test_btanalysis.py +++ b/freqtrade/tests/data/test_btanalysis.py @@ -45,6 +45,11 @@ def test_load_trades_db(default_conf, fee, mocker): assert isinstance(trades, DataFrame) assert "pair" in trades.columns assert "open_time" in trades.columns + assert "profitperc" in trades.columns + + for col in BT_DATA_COLUMNS: + if col not in ['index', 'open_at_end']: + assert col in trades.columns def test_extract_trades_of_period(): From 4d1ce8178c8abc55488932f07b20055c08497312 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 4 Aug 2019 10:38:37 +0200 Subject: [PATCH 2/2] intend if to be clearer --- freqtrade/data/btanalysis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py index 6568fe31e..36d8aedbb 100644 --- a/freqtrade/data/btanalysis.py +++ b/freqtrade/data/btanalysis.py @@ -93,8 +93,8 @@ def load_trades_from_db(db_url: str) -> pd.DataFrame: t.close_date.replace(tzinfo=pytz.UTC) if t.close_date else None, t.calc_profit(), t.calc_profit_percent(), t.open_rate, t.close_rate, t.amount, - t.close_date.timestamp() - t.open_date.timestamp() - if t.close_date else None, + (t.close_date.timestamp() - t.open_date.timestamp() + if t.close_date else None), t.sell_reason, t.fee_open, t.fee_close, t.open_rate_requested,