2828 Bybit ,
2929 Exchange ,
3030 Kraken ,
31+ date_minus_candles ,
3132 market_is_active ,
3233 timeframe_to_prev_date ,
3334)
@@ -2144,7 +2145,7 @@ def test___now_is_time_to_refresh(default_conf, mocker, exchange_name, time_mach
21442145 assert exchange ._now_is_time_to_refresh (pair , "1d" , candle_type ) is True
21452146
21462147
2147- @pytest .mark .parametrize ("candle_type" , ["mark" , "" ])
2148+ @pytest .mark .parametrize ("candle_type" , ["mark" , "spot " ])
21482149@pytest .mark .parametrize ("exchange_name" , EXCHANGES )
21492150def test_get_historic_ohlcv (default_conf , mocker , caplog , exchange_name , candle_type ):
21502151 caplog .set_level (logging .DEBUG )
@@ -2171,24 +2172,24 @@ async def mock_candle_hist(pair, timeframe, candle_type, since_ms):
21712172
21722173 exchange ._async_get_candle_history = Mock (wraps = mock_candle_hist )
21732174 # one_call calculation * 1.8 should do 2 calls
2175+ candle_limit = exchange .ohlcv_candle_limit ("5m" , candle_type )
2176+ since = date_minus_candles ("5m" , candle_limit )
2177+ ret = exchange .get_historic_ohlcv (pair , "5m" , dt_ts (since ), candle_type = candle_type )
21742178
2175- since = 5 * 60 * exchange .ohlcv_candle_limit ("5m" , candle_type ) * 1.8
2176- ret = exchange .get_historic_ohlcv (
2177- pair , "5m" , dt_ts (dt_now () - timedelta (seconds = since )), candle_type = candle_type
2178- )
2179-
2180- assert exchange ._async_get_candle_history .call_count == 2
2179+ if exchange_name == "okx" and candle_type == "mark" :
2180+ expected = 4
2181+ else :
2182+ expected = 2
2183+ assert exchange ._async_get_candle_history .call_count == expected
21812184 # Returns twice the above OHLCV data after truncating the open candle.
2182- assert len (ret ) == 2
2185+ assert len (ret ) == expected
21832186 assert log_has_re (r"Downloaded data for .* from ccxt with length .*\." , caplog )
21842187
21852188 caplog .clear ()
21862189
21872190 exchange ._async_get_candle_history = get_mock_coro (side_effect = TimeoutError ())
21882191 with pytest .raises (TimeoutError ):
2189- exchange .get_historic_ohlcv (
2190- pair , "5m" , dt_ts (dt_now () - timedelta (seconds = since )), candle_type = candle_type
2191- )
2192+ exchange .get_historic_ohlcv (pair , "5m" , dt_ts (since ), candle_type = candle_type )
21922193 assert log_has_re (r"Async code raised an exception: .*" , caplog )
21932194
21942195
0 commit comments