mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-14 04:03:55 +00:00
chore: update patch_exchange to not override builtins
This commit is contained in:
parent
1e287de589
commit
36a44575c7
|
@ -167,7 +167,7 @@ def test_list_timeframes(mocker, capsys):
|
||||||
"1h": "hour",
|
"1h": "hour",
|
||||||
"1d": "day",
|
"1d": "day",
|
||||||
}
|
}
|
||||||
patch_exchange(mocker, api_mock=api_mock, id="bybit")
|
patch_exchange(mocker, api_mock=api_mock, exchange="bybit")
|
||||||
args = [
|
args = [
|
||||||
"list-timeframes",
|
"list-timeframes",
|
||||||
]
|
]
|
||||||
|
@ -213,7 +213,7 @@ def test_list_timeframes(mocker, capsys):
|
||||||
"1d": "1d",
|
"1d": "1d",
|
||||||
"3d": "3d",
|
"3d": "3d",
|
||||||
}
|
}
|
||||||
patch_exchange(mocker, api_mock=api_mock, id="binance")
|
patch_exchange(mocker, api_mock=api_mock, exchange="binance")
|
||||||
# Test with --exchange binance
|
# Test with --exchange binance
|
||||||
args = [
|
args = [
|
||||||
"list-timeframes",
|
"list-timeframes",
|
||||||
|
@ -258,7 +258,7 @@ def test_list_timeframes(mocker, capsys):
|
||||||
|
|
||||||
def test_list_markets(mocker, markets_static, capsys):
|
def test_list_markets(mocker, markets_static, capsys):
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
patch_exchange(mocker, api_mock=api_mock, id="binance", mock_markets=markets_static)
|
patch_exchange(mocker, api_mock=api_mock, exchange="binance", mock_markets=markets_static)
|
||||||
|
|
||||||
# Test with no --config
|
# Test with no --config
|
||||||
args = [
|
args = [
|
||||||
|
@ -286,7 +286,7 @@ def test_list_markets(mocker, markets_static, capsys):
|
||||||
"LTC/ETH, LTC/USD, NEO/BTC, TKN/BTC, XLTCUSDT, XRP/BTC.\n" in captured.out
|
"LTC/ETH, LTC/USD, NEO/BTC, TKN/BTC, XLTCUSDT, XRP/BTC.\n" in captured.out
|
||||||
)
|
)
|
||||||
|
|
||||||
patch_exchange(mocker, api_mock=api_mock, id="binance", mock_markets=markets_static)
|
patch_exchange(mocker, api_mock=api_mock, exchange="binance", mock_markets=markets_static)
|
||||||
# Test with --exchange
|
# Test with --exchange
|
||||||
args = ["list-markets", "--exchange", "binance"]
|
args = ["list-markets", "--exchange", "binance"]
|
||||||
pargs = get_args(args)
|
pargs = get_args(args)
|
||||||
|
@ -295,7 +295,7 @@ def test_list_markets(mocker, markets_static, capsys):
|
||||||
captured = capsys.readouterr()
|
captured = capsys.readouterr()
|
||||||
assert re.match("\nExchange Binance has 12 active markets:\n", captured.out)
|
assert re.match("\nExchange Binance has 12 active markets:\n", captured.out)
|
||||||
|
|
||||||
patch_exchange(mocker, api_mock=api_mock, id="binance", mock_markets=markets_static)
|
patch_exchange(mocker, api_mock=api_mock, exchange="binance", mock_markets=markets_static)
|
||||||
# Test with --all: all markets
|
# Test with --all: all markets
|
||||||
args = [
|
args = [
|
||||||
"list-markets",
|
"list-markets",
|
||||||
|
@ -823,7 +823,7 @@ def test_download_data_no_markets(mocker, caplog):
|
||||||
"freqtrade.data.history.history_utils.refresh_backtest_ohlcv_data",
|
"freqtrade.data.history.history_utils.refresh_backtest_ohlcv_data",
|
||||||
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]),
|
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]),
|
||||||
)
|
)
|
||||||
patch_exchange(mocker, id="binance")
|
patch_exchange(mocker, exchange="binance")
|
||||||
mocker.patch(f"{EXMS}.get_markets", return_value={})
|
mocker.patch(f"{EXMS}.get_markets", return_value={})
|
||||||
args = [
|
args = [
|
||||||
"download-data",
|
"download-data",
|
||||||
|
@ -952,7 +952,7 @@ def test_download_data_trades(mocker):
|
||||||
|
|
||||||
|
|
||||||
def test_download_data_data_invalid(mocker):
|
def test_download_data_data_invalid(mocker):
|
||||||
patch_exchange(mocker, id="kraken")
|
patch_exchange(mocker, exchange="kraken")
|
||||||
mocker.patch(f"{EXMS}.get_markets", return_value={})
|
mocker.patch(f"{EXMS}.get_markets", return_value={})
|
||||||
args = [
|
args = [
|
||||||
"download-data",
|
"download-data",
|
||||||
|
|
|
@ -137,7 +137,7 @@ def generate_trades_history(n_rows, start_date: Optional[datetime] = None, days=
|
||||||
random_timestamps_in_seconds = np.random.uniform(_start_timestamp, _end_timestamp, n_rows)
|
random_timestamps_in_seconds = np.random.uniform(_start_timestamp, _end_timestamp, n_rows)
|
||||||
timestamp = pd.to_datetime(random_timestamps_in_seconds, unit="s")
|
timestamp = pd.to_datetime(random_timestamps_in_seconds, unit="s")
|
||||||
|
|
||||||
id = [
|
trade_id = [
|
||||||
f"a{np.random.randint(1e6, 1e7 - 1)}cd{np.random.randint(100, 999)}" for _ in range(n_rows)
|
f"a{np.random.randint(1e6, 1e7 - 1)}cd{np.random.randint(100, 999)}" for _ in range(n_rows)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ def generate_trades_history(n_rows, start_date: Optional[datetime] = None, days=
|
||||||
df = pd.DataFrame(
|
df = pd.DataFrame(
|
||||||
{
|
{
|
||||||
"timestamp": timestamp,
|
"timestamp": timestamp,
|
||||||
"id": id,
|
"id": trade_id,
|
||||||
"type": None,
|
"type": None,
|
||||||
"side": side,
|
"side": side,
|
||||||
"price": price,
|
"price": price,
|
||||||
|
@ -236,12 +236,12 @@ def patched_configuration_load_config_file(mocker, config) -> None:
|
||||||
|
|
||||||
|
|
||||||
def patch_exchange(
|
def patch_exchange(
|
||||||
mocker, api_mock=None, id="binance", mock_markets=True, mock_supported_modes=True
|
mocker, api_mock=None, exchange="binance", mock_markets=True, mock_supported_modes=True
|
||||||
) -> None:
|
) -> None:
|
||||||
mocker.patch(f"{EXMS}.validate_config", MagicMock())
|
mocker.patch(f"{EXMS}.validate_config", MagicMock())
|
||||||
mocker.patch(f"{EXMS}.validate_timeframes", MagicMock())
|
mocker.patch(f"{EXMS}.validate_timeframes", MagicMock())
|
||||||
mocker.patch(f"{EXMS}.id", PropertyMock(return_value=id))
|
mocker.patch(f"{EXMS}.id", PropertyMock(return_value=exchange))
|
||||||
mocker.patch(f"{EXMS}.name", PropertyMock(return_value=id.title()))
|
mocker.patch(f"{EXMS}.name", PropertyMock(return_value=exchange.title()))
|
||||||
mocker.patch(f"{EXMS}.precisionMode", PropertyMock(return_value=2))
|
mocker.patch(f"{EXMS}.precisionMode", PropertyMock(return_value=2))
|
||||||
# Temporary patch ...
|
# Temporary patch ...
|
||||||
mocker.patch("freqtrade.exchange.bybit.Bybit.cache_leverage_tiers")
|
mocker.patch("freqtrade.exchange.bybit.Bybit.cache_leverage_tiers")
|
||||||
|
@ -254,7 +254,8 @@ def patch_exchange(
|
||||||
|
|
||||||
if mock_supported_modes:
|
if mock_supported_modes:
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
f"freqtrade.exchange.{id}.{id.capitalize()}._supported_trading_mode_margin_pairs",
|
f"freqtrade.exchange.{exchange}.{exchange.capitalize()}"
|
||||||
|
"._supported_trading_mode_margin_pairs",
|
||||||
PropertyMock(
|
PropertyMock(
|
||||||
return_value=[
|
return_value=[
|
||||||
(TradingMode.MARGIN, MarginMode.CROSS),
|
(TradingMode.MARGIN, MarginMode.CROSS),
|
||||||
|
|
|
@ -14,7 +14,7 @@ def test_download_data_main_no_markets(mocker, caplog):
|
||||||
"freqtrade.data.history.history_utils.refresh_backtest_ohlcv_data",
|
"freqtrade.data.history.history_utils.refresh_backtest_ohlcv_data",
|
||||||
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]),
|
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]),
|
||||||
)
|
)
|
||||||
patch_exchange(mocker, id="binance")
|
patch_exchange(mocker, exchange="binance")
|
||||||
mocker.patch(f"{EXMS}.get_markets", return_value={})
|
mocker.patch(f"{EXMS}.get_markets", return_value={})
|
||||||
config = setup_utils_configuration({"exchange": "binance"}, RunMode.UTIL_EXCHANGE)
|
config = setup_utils_configuration({"exchange": "binance"}, RunMode.UTIL_EXCHANGE)
|
||||||
config.update({"days": 20, "pairs": ["ETH/BTC", "XRP/BTC"], "timeframes": ["5m", "1h"]})
|
config.update({"days": 20, "pairs": ["ETH/BTC", "XRP/BTC"], "timeframes": ["5m", "1h"]})
|
||||||
|
@ -91,7 +91,7 @@ def test_download_data_main_trades(mocker):
|
||||||
|
|
||||||
|
|
||||||
def test_download_data_main_data_invalid(mocker):
|
def test_download_data_main_data_invalid(mocker):
|
||||||
patch_exchange(mocker, id="kraken")
|
patch_exchange(mocker, exchange="kraken")
|
||||||
mocker.patch(f"{EXMS}.get_markets", return_value={})
|
mocker.patch(f"{EXMS}.get_markets", return_value={})
|
||||||
config = setup_utils_configuration({"exchange": "kraken"}, RunMode.UTIL_EXCHANGE)
|
config = setup_utils_configuration({"exchange": "kraken"}, RunMode.UTIL_EXCHANGE)
|
||||||
config.update(
|
config.update(
|
||||||
|
|
|
@ -17,7 +17,7 @@ def test_import_kraken_trades_from_csv(testdatadir, tmp_path, caplog, default_co
|
||||||
|
|
||||||
default_conf_usdt["exchange"]["name"] = "kraken"
|
default_conf_usdt["exchange"]["name"] = "kraken"
|
||||||
|
|
||||||
patch_exchange(mocker, id="kraken")
|
patch_exchange(mocker, exchange="kraken")
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
f"{EXMS}.markets",
|
f"{EXMS}.markets",
|
||||||
PropertyMock(
|
PropertyMock(
|
||||||
|
|
|
@ -915,7 +915,7 @@ def test_execute_entry(
|
||||||
default_conf_usdt["margin_mode"] = margin_mode
|
default_conf_usdt["margin_mode"] = margin_mode
|
||||||
mocker.patch("freqtrade.exchange.gate.Gate.validate_ordertypes")
|
mocker.patch("freqtrade.exchange.gate.Gate.validate_ordertypes")
|
||||||
patch_RPCManager(mocker)
|
patch_RPCManager(mocker)
|
||||||
patch_exchange(mocker, id=exchange_name)
|
patch_exchange(mocker, exchange=exchange_name)
|
||||||
freqtrade = FreqtradeBot(default_conf_usdt)
|
freqtrade = FreqtradeBot(default_conf_usdt)
|
||||||
freqtrade.strategy.confirm_trade_entry = MagicMock(return_value=False)
|
freqtrade.strategy.confirm_trade_entry = MagicMock(return_value=False)
|
||||||
freqtrade.strategy.leverage = MagicMock(return_value=leverage)
|
freqtrade.strategy.leverage = MagicMock(return_value=leverage)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user