|
18 | 18 | from freqtrade.data.history import get_datahandler |
19 | 19 | from freqtrade.data.history.datahandlers.jsondatahandler import JsonDataHandler, JsonGzDataHandler |
20 | 20 | from freqtrade.data.history.history_utils import ( |
| 21 | + _download_all_pairs_history_parallel, |
21 | 22 | _download_pair_history, |
22 | 23 | _download_trades_history, |
23 | 24 | _load_cached_data_for_updating, |
@@ -708,3 +709,82 @@ def test_download_trades_history( |
708 | 709 | assert ght_mock.call_count == 0 |
709 | 710 |
|
710 | 711 | _clean_test_file(file2) |
| 712 | + |
| 713 | + |
| 714 | +def test_download_all_pairs_history_parallel(mocker, default_conf_usdt): |
| 715 | + pairs = ["PAIR1/BTC", "PAIR2/USDT"] |
| 716 | + timeframe = "5m" |
| 717 | + candle_type = CandleType.SPOT |
| 718 | + |
| 719 | + df1 = DataFrame( |
| 720 | + { |
| 721 | + "date": [1, 2], |
| 722 | + "open": [1, 2], |
| 723 | + "close": [1, 2], |
| 724 | + "high": [1, 2], |
| 725 | + "low": [1, 2], |
| 726 | + "volume": [1, 2], |
| 727 | + } |
| 728 | + ) |
| 729 | + df2 = DataFrame( |
| 730 | + { |
| 731 | + "date": [3, 4], |
| 732 | + "open": [3, 4], |
| 733 | + "close": [3, 4], |
| 734 | + "high": [3, 4], |
| 735 | + "low": [3, 4], |
| 736 | + "volume": [3, 4], |
| 737 | + } |
| 738 | + ) |
| 739 | + expected = { |
| 740 | + ("PAIR1/BTC", timeframe, candle_type): df1, |
| 741 | + ("PAIR2/USDT", timeframe, candle_type): df2, |
| 742 | + } |
| 743 | + # Mock exchange |
| 744 | + mocker.patch.multiple( |
| 745 | + EXMS, |
| 746 | + exchange_has=MagicMock(return_value=True), |
| 747 | + ohlcv_candle_limit=MagicMock(return_value=1000), |
| 748 | + refresh_latest_ohlcv=MagicMock(return_value=expected), |
| 749 | + ) |
| 750 | + exchange = get_patched_exchange(mocker, default_conf_usdt) |
| 751 | + # timerange with starttype 'date' and startts far in the future to trigger parallel download |
| 752 | + |
| 753 | + timerange = TimeRange("date", None, 9999999999, 0) |
| 754 | + result = _download_all_pairs_history_parallel( |
| 755 | + exchange=exchange, |
| 756 | + pairs=pairs, |
| 757 | + timeframe=timeframe, |
| 758 | + candle_type=candle_type, |
| 759 | + timerange=timerange, |
| 760 | + ) |
| 761 | + assert result == expected |
| 762 | + |
| 763 | + assert exchange.ohlcv_candle_limit.call_args[0] == (timeframe, candle_type) |
| 764 | + assert exchange.refresh_latest_ohlcv.call_count == 1 |
| 765 | + |
| 766 | + # If since is not after one_call_min_time_dt, should not call refresh_latest_ohlcv |
| 767 | + exchange.refresh_latest_ohlcv.reset_mock() |
| 768 | + timerange2 = TimeRange("date", None, 0, 0) |
| 769 | + result2 = _download_all_pairs_history_parallel( |
| 770 | + exchange=exchange, |
| 771 | + pairs=pairs, |
| 772 | + timeframe=timeframe, |
| 773 | + candle_type=candle_type, |
| 774 | + timerange=timerange2, |
| 775 | + ) |
| 776 | + assert result2 == {} |
| 777 | + assert exchange.refresh_latest_ohlcv.call_count == 0 |
| 778 | + |
| 779 | + exchange.refresh_latest_ohlcv.reset_mock() |
| 780 | + |
| 781 | + # Test without timerange |
| 782 | + result3 = _download_all_pairs_history_parallel( |
| 783 | + exchange=exchange, |
| 784 | + pairs=pairs, |
| 785 | + timeframe=timeframe, |
| 786 | + candle_type=candle_type, |
| 787 | + timerange=None, |
| 788 | + ) |
| 789 | + assert result3 == {} |
| 790 | + assert exchange.refresh_latest_ohlcv.call_count == 0 |
0 commit comments