diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py index 7b0109fa9..1d580a7dd 100644 --- a/freqtrade/data/btanalysis.py +++ b/freqtrade/data/btanalysis.py @@ -376,7 +376,7 @@ def load_backtest_data(filename: Path | str, strategy: str | None = None) -> pd. if not strategy: if len(data["strategy"]) == 1: - strategy = list(data["strategy"].keys())[0] + strategy = next(iter(data["strategy"].keys())) else: raise ValueError( "Detected backtest result with more than one strategy. " diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 411c585fc..00cd19591 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -1366,8 +1366,8 @@ class Exchange: ordertype = available_order_Types[user_order_type] else: # Otherwise pick only one available - ordertype = list(available_order_Types.values())[0] - user_order_type = list(available_order_Types.keys())[0] + ordertype = next(iter(available_order_Types.values())) + user_order_type = next(iter(available_order_Types.keys())) return ordertype, user_order_type def _get_stop_limit_rate(self, stop_price: float, order_types: dict, side: str) -> float: diff --git a/tests/exchange/test_binance.py b/tests/exchange/test_binance.py index 998952b33..5241b3b69 100644 --- a/tests/exchange/test_binance.py +++ b/tests/exchange/test_binance.py @@ -299,7 +299,7 @@ def test_liquidation_price_binance( def get_maint_ratio(pair_, stake_amount): if pair_ != pair: - oc = [c for c in open_trades if c["pair"] == pair_][0] + oc = next(c for c in open_trades if c["pair"] == pair_) return oc["mm_ratio"], oc["maintenance_amt"] return mm_ratio, maintenance_amt diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index 62a054313..6261f1ae1 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -2206,8 +2206,8 @@ def test_api_pair_history(botclient, tmp_path, mocker): assert len(result["columns"]) == col_count assert len(result["all_columns"]) == 25 assert len(data[0]) == col_count - date_col_idx = [idx for idx, c in enumerate(result["columns"]) if c == "date"][0] - rsi_col_idx = [idx for idx, c in enumerate(result["columns"]) if c == "rsi"][0] + date_col_idx = next(idx for idx, c in enumerate(result["columns"]) if c == "date") + rsi_col_idx = next(idx for idx, c in enumerate(result["columns"]) if c == "rsi") assert data[0][date_col_idx] == "2018-01-11T00:00:00Z" assert data[0][rsi_col_idx] is not None @@ -2432,7 +2432,7 @@ def test_api_exchanges(botclient): response = rc.json() assert isinstance(response["exchanges"], list) assert len(response["exchanges"]) > 20 - okx = [x for x in response["exchanges"] if x["classname"] == "okx"][0] + okx = next(x for x in response["exchanges"] if x["classname"] == "okx") assert okx == { "classname": "okx", "name": "OKX", @@ -2448,7 +2448,7 @@ def test_api_exchanges(botclient): ], } - mexc = [x for x in response["exchanges"] if x["classname"] == "mexc"][0] + mexc = next(x for x in response["exchanges"] if x["classname"] == "mexc") assert mexc == { "classname": "mexc", "name": "MEXC Global", @@ -2460,7 +2460,7 @@ def test_api_exchanges(botclient): "alias_for": None, "trade_modes": [{"trading_mode": "spot", "margin_mode": ""}], } - waves = [x for x in response["exchanges"] if x["classname"] == "wavesexchange"][0] + waves = next(x for x in response["exchanges"] if x["classname"] == "wavesexchange") assert waves == { "classname": "wavesexchange", "name": "Waves.Exchange", @@ -2554,10 +2554,10 @@ def test_api_pairlists_available(botclient, tmp_path): assert len([r for r in response["pairlists"] if r["name"] == "VolumePairList"]) == 1 assert len([r for r in response["pairlists"] if r["name"] == "StaticPairList"]) == 1 - volumepl = [r for r in response["pairlists"] if r["name"] == "VolumePairList"][0] + volumepl = next(r for r in response["pairlists"] if r["name"] == "VolumePairList") assert volumepl["is_pairlist_generator"] is True assert len(volumepl["params"]) > 1 - age_pl = [r for r in response["pairlists"] if r["name"] == "AgeFilter"][0] + age_pl = next(r for r in response["pairlists"] if r["name"] == "AgeFilter") assert age_pl["is_pairlist_generator"] is False assert len(volumepl["params"]) > 2