|
5 | 5 | import asyncio |
6 | 6 | import logging |
7 | 7 | import time |
| 8 | +from copy import deepcopy |
8 | 9 | from datetime import UTC, datetime, timedelta |
9 | 10 | from pathlib import Path |
10 | 11 | from unittest.mock import ANY, MagicMock, PropertyMock |
@@ -1860,7 +1861,42 @@ def test_api_forceexit(botclient, mocker, ticker, fee, markets): |
1860 | 1861 | assert trade.is_open is False |
1861 | 1862 |
|
1862 | 1863 |
|
1863 | | -def test_api_pair_candles(botclient, ohlcv_history): |
| 1864 | +def gen_annotation_params(): |
| 1865 | + area_annotation = { |
| 1866 | + "type": "area", |
| 1867 | + "start": "2024-01-01 15:00:00", |
| 1868 | + "end": "2024-01-01 16:00:00", |
| 1869 | + "y_start": 94000.2, |
| 1870 | + "y_end": 98000, |
| 1871 | + "color": "", |
| 1872 | + "label": "some label", |
| 1873 | + } |
| 1874 | + line_annotation = { |
| 1875 | + "type": "line", |
| 1876 | + "start": "2024-01-01 15:00:00", |
| 1877 | + "end": "2024-01-01 16:00:00", |
| 1878 | + "y_start": 99000.2, |
| 1879 | + "y_end": 98000, |
| 1880 | + "color": "", |
| 1881 | + "label": "some label", |
| 1882 | + "width": 2, |
| 1883 | + "line_style": "dashed", |
| 1884 | + } |
| 1885 | + |
| 1886 | + line_wrong = deepcopy(line_annotation) |
| 1887 | + line_wrong["line_style"] = "dashed2222" |
| 1888 | + return [ |
| 1889 | + ([area_annotation], [area_annotation]), # Only area |
| 1890 | + ([line_annotation], [line_annotation]), # Only line |
| 1891 | + ([area_annotation, line_annotation], [area_annotation, line_annotation]), # Both together |
| 1892 | + ([], []), # Empty |
| 1893 | + ([line_wrong], []), # Invalid line |
| 1894 | + ([area_annotation, line_wrong], [area_annotation]), # Invalid line |
| 1895 | + ] |
| 1896 | + |
| 1897 | + |
| 1898 | +@pytest.mark.parametrize("annotations,expected", gen_annotation_params()) |
| 1899 | +def test_api_pair_candles(botclient, ohlcv_history, annotations, expected): |
1864 | 1900 | ftbot, client = botclient |
1865 | 1901 | timeframe = "5m" |
1866 | 1902 | amount = 3 |
@@ -1892,29 +1928,7 @@ def test_api_pair_candles(botclient, ohlcv_history): |
1892 | 1928 | ohlcv_history["exit_short"] = 0 |
1893 | 1929 |
|
1894 | 1930 | ftbot.dataprovider._set_cached_df("XRP/BTC", timeframe, ohlcv_history, CandleType.SPOT) |
1895 | | - fake_plot_annotations = [ |
1896 | | - { |
1897 | | - "type": "area", |
1898 | | - "start": "2024-01-01 15:00:00", |
1899 | | - "end": "2024-01-01 16:00:00", |
1900 | | - "y_start": 94000.2, |
1901 | | - "y_end": 98000, |
1902 | | - "color": "", |
1903 | | - "label": "some label", |
1904 | | - }, |
1905 | | - { |
1906 | | - "type": "line", |
1907 | | - "start": "2024-01-01 15:00:00", |
1908 | | - "end": "2024-01-01 16:00:00", |
1909 | | - "y_start": 99000.2, |
1910 | | - "y_end": 98000, |
1911 | | - "color": "", |
1912 | | - "label": "some label", |
1913 | | - "width": 2, |
1914 | | - "line_style": "dashed", |
1915 | | - }, |
1916 | | - ] |
1917 | | - plot_annotations_mock = MagicMock(return_value=fake_plot_annotations) |
| 1931 | + plot_annotations_mock = MagicMock(return_value=annotations) |
1918 | 1932 | ftbot.strategy.plot_annotations = plot_annotations_mock |
1919 | 1933 | for call in ("get", "post"): |
1920 | 1934 | plot_annotations_mock.reset_mock() |
@@ -1947,7 +1961,7 @@ def test_api_pair_candles(botclient, ohlcv_history): |
1947 | 1961 | assert resp["data_start_ts"] == 1511686200000 |
1948 | 1962 | assert resp["data_stop"] == "2017-11-26 09:00:00+00:00" |
1949 | 1963 | assert resp["data_stop_ts"] == 1511686800000 |
1950 | | - assert resp["annotations"] == fake_plot_annotations |
| 1964 | + assert resp["annotations"] == expected |
1951 | 1965 | assert plot_annotations_mock.call_count == 1 |
1952 | 1966 | assert isinstance(resp["columns"], list) |
1953 | 1967 | base_cols = { |
|
0 commit comments