chore: update attribute wording to bt_trades

This commit is contained in:
Matthias 2024-08-12 10:37:56 +02:00
parent e643a2ea32
commit 2bc9cdafb2
6 changed files with 14 additions and 14 deletions

View File

@ -1491,7 +1491,7 @@ class Backtesting:
self.handle_left_open(LocalTrade.bt_trades_open_pp, data=data)
self.wallets.update()
results = trade_list_to_dataframe(LocalTrade.trades)
results = trade_list_to_dataframe(LocalTrade.bt_trades)
return {
"results": results,
"config": self.strategy.config,

View File

@ -373,7 +373,7 @@ class LocalTrade:
use_db: bool = False
# Trades container for backtesting
trades: List["LocalTrade"] = []
bt_trades: List["LocalTrade"] = []
bt_trades_open: List["LocalTrade"] = []
# Copy of trades_open - but indexed by pair
bt_trades_open_pp: Dict[str, List["LocalTrade"]] = defaultdict(list)
@ -740,7 +740,7 @@ class LocalTrade:
"""
Resets all trades. Only active for backtesting mode.
"""
LocalTrade.trades = []
LocalTrade.bt_trades = []
LocalTrade.bt_trades_open = []
LocalTrade.bt_trades_open_pp = defaultdict(list)
LocalTrade.bt_open_open_trade_count = 0
@ -1405,7 +1405,7 @@ class LocalTrade:
Helper function to query Trades.
Returns a List of trades, filtered on the parameters given.
In live mode, converts the filter to a database query and returns all rows
In Backtest mode, uses filters on Trade.trades to get the result.
In Backtest mode, uses filters on Trade.bt_trades to get the result.
:param pair: Filter by pair
:param is_open: Filter by open/closed status
@ -1420,11 +1420,11 @@ class LocalTrade:
if is_open:
sel_trades = LocalTrade.bt_trades_open
else:
sel_trades = LocalTrade.trades
sel_trades = LocalTrade.bt_trades
else:
# Not used during backtesting, but might be used by a strategy
sel_trades = list(LocalTrade.trades + LocalTrade.bt_trades_open)
sel_trades = list(LocalTrade.bt_trades + LocalTrade.bt_trades_open)
if pair:
sel_trades = [trade for trade in sel_trades if trade.pair == pair]
@ -1442,7 +1442,7 @@ class LocalTrade:
LocalTrade.bt_trades_open.remove(trade)
LocalTrade.bt_trades_open_pp[trade.pair].remove(trade)
LocalTrade.bt_open_open_trade_count -= 1
LocalTrade.trades.append(trade)
LocalTrade.bt_trades.append(trade)
LocalTrade.total_profit += trade.close_profit_abs
@staticmethod
@ -1452,7 +1452,7 @@ class LocalTrade:
LocalTrade.bt_trades_open_pp[trade.pair].append(trade)
LocalTrade.bt_open_open_trade_count += 1
else:
LocalTrade.trades.append(trade)
LocalTrade.bt_trades.append(trade)
@staticmethod
def remove_bt_trade(trade):
@ -1761,7 +1761,7 @@ class Trade(ModelBase, LocalTrade):
Helper function to query Trades.j
Returns a List of trades, filtered on the parameters given.
In live mode, converts the filter to a database query and returns all rows
In Backtest mode, uses filters on Trade.trades to get the result.
In Backtest mode, uses filters on Trade.bt_trades to get the result.
:return: unsorted List[Trade]
"""

View File

@ -182,7 +182,7 @@ def api_get_backtest():
ApiBG.bt["bt"].progress.action if ApiBG.bt["bt"] else str(BacktestState.STARTUP)
),
"progress": ApiBG.bt["bt"].progress.progress if ApiBG.bt["bt"] else 0,
"trade_count": len(LocalTrade.trades),
"trade_count": len(LocalTrade.bt_trades),
"status_msg": "Backtest running",
}

View File

@ -1249,7 +1249,7 @@ def test_backtest_results(default_conf, mocker, caplog, data: BTContainer) -> No
assert res.open_date == _get_frame_time_from_offset(trade.open_tick)
assert res.close_date == _get_frame_time_from_offset(trade.close_tick)
assert res.is_short == trade.is_short
assert len(LocalTrade.trades) == len(data.trades)
assert len(LocalTrade.bt_trades) == len(data.trades)
assert len(LocalTrade.bt_trades_open) == 0
backtesting.cleanup()
del backtesting

View File

@ -1041,7 +1041,7 @@ def test_backtest_one_detail_futures(
<= round(t["close_rate"], 6)
<= round(ln2.iloc[0]["high"], 6)
)
assert pytest.approx(Trade.trades[1].funding_fees) == exp_funding_fee
assert pytest.approx(Trade.bt_trades[1].funding_fees) == exp_funding_fee
assert ff_spy.call_count == exp_ff_updates
# assert late_entry > 0
@ -1136,7 +1136,7 @@ def test_backtest_one_detail_futures_funding_fees(
# Additional counts will happen due each successful entry, which needs to call this, too.
assert ff_spy.call_count == ff_updates
for t in Trade.trades:
for t in Trade.bt_trades:
# At least 6 adjustment orders
assert t.nr_of_successful_entries == entries
# Funding fees will vary depending on the number of adjustment orders

View File

@ -2136,7 +2136,7 @@ def test_Trade_object_idem():
"custom_data",
)
EXCLUDES2 = (
"trades",
"bt_trades",
"bt_trades_open",
"bt_trades_open_pp",
"bt_open_open_trade_count",