Fix sequence of loading trades
This commit is contained in:
@@ -73,37 +73,45 @@ def evaluate_result_multi(results: pd.DataFrame, freq: str, max_open_trades: int
|
||||
return df_final[df_final['pair'] > max_open_trades]
|
||||
|
||||
|
||||
def load_trades(db_url: str = None, exportfilename: str = None) -> pd.DataFrame:
|
||||
def load_trades_from_db(db_url: str) -> pd.DataFrame:
|
||||
"""
|
||||
Load trades, either from a DB (using dburl) or via a backtest export file.
|
||||
Load trades from a DB (using dburl)
|
||||
:param db_url: Sqlite url (default format sqlite:///tradesv3.dry-run.sqlite)
|
||||
:param exportfilename: Path to a file exported from backtesting
|
||||
:returns: Dataframe containing Trades
|
||||
"""
|
||||
timeZone = pytz.UTC
|
||||
|
||||
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"]
|
||||
|
||||
if db_url:
|
||||
persistence.init(db_url, clean_open_orders=False)
|
||||
columns = ["pair", "profit", "open_time", "close_time",
|
||||
"open_rate", "close_rate", "duration"]
|
||||
|
||||
for x in Trade.query.all():
|
||||
logger.info("date: {}".format(x.open_date))
|
||||
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=timeZone),
|
||||
t.close_date.replace(tzinfo=timeZone) if t.close_date else None,
|
||||
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)
|
||||
|
||||
elif exportfilename:
|
||||
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
|
||||
|
||||
|
Reference in New Issue
Block a user