@@ -245,3 +245,120 @@ def test_historical_kline_generator_empty_response():
245245
246246 with pytest .raises (StopIteration ):
247247 next (klines )
248+
249+
250+ def test_historical_kline_with_month_interval ():
251+ """Test historical klines with one month interval"""
252+
253+ first_available_res = [
254+ [
255+ 1498867200000 ,
256+ "0.00005000" ,
257+ "0.00005480" ,
258+ "0.00001000" ,
259+ "0.00003654" ,
260+ "61059068.00000000" ,
261+ 1501545599999 ,
262+ "2572.23205388" ,
263+ 33297 ,
264+ "33906053.00000000" ,
265+ "1442.17447471" ,
266+ "100206524.84393587"
267+ ]
268+ ]
269+ first_res = []
270+ row = [
271+ 1519862400000 ,
272+ "0.00101270" ,
273+ "0.00167650" ,
274+ "0.00083250" ,
275+ "0.00159650" ,
276+ "122814213.69000000" ,
277+ 1522540799999 ,
278+ "142681.39725065" ,
279+ 3242765 ,
280+ "68994444.35000000" ,
281+ "79545.22096745" ,
282+ "0"
283+ ]
284+
285+ for i in range (0 , 8 ):
286+ first_res .append (row )
287+
288+ with requests_mock .mock () as m :
289+ m .get (
290+ "https://api.binance.com/api/v1/klines?interval=1M&limit=1&startTime=0&symbol=BNBBTC" ,
291+ json = first_available_res ,
292+ )
293+ m .get (
294+ "https://api.binance.com/api/v1/klines?interval=1M&limit=500&startTime=1519862400000&endTime=1539234000000&symbol=BNBBTC" ,
295+ json = first_res ,
296+ )
297+ klines = client .get_historical_klines (
298+ symbol = "BNBBTC" ,
299+ interval = Client .KLINE_INTERVAL_1MONTH ,
300+ start_str = "1st March 2018" ,
301+ end_str = "11st Oct 2018 05:00:00" ,
302+ )
303+ assert len (klines ) == 8
304+
305+
306+ def test_historical_kline_generator_with_month_interval ():
307+ """Test historical klines generator with one month interval"""
308+
309+ first_available_res = [
310+ [
311+ 1498867200000 ,
312+ "0.00005000" ,
313+ "0.00005480" ,
314+ "0.00001000" ,
315+ "0.00003654" ,
316+ "61059068.00000000" ,
317+ 1501545599999 ,
318+ "2572.23205388" ,
319+ 33297 ,
320+ "33906053.00000000" ,
321+ "1442.17447471" ,
322+ "100206524.84393587"
323+ ]
324+ ]
325+ first_res = []
326+ row = [
327+ 1519862400000 ,
328+ "0.00101270" ,
329+ "0.00167650" ,
330+ "0.00083250" ,
331+ "0.00159650" ,
332+ "122814213.69000000" ,
333+ 1522540799999 ,
334+ "142681.39725065" ,
335+ 3242765 ,
336+ "68994444.35000000" ,
337+ "79545.22096745" ,
338+ "0"
339+ ]
340+
341+ for i in range (0 , 8 ):
342+ first_res .append (row )
343+
344+ with requests_mock .mock () as m :
345+ m .get (
346+ "https://api.binance.com/api/v1/klines?interval=1M&limit=1&startTime=0&symbol=BNBBTC" ,
347+ json = first_available_res ,
348+ )
349+ m .get (
350+ "https://api.binance.com/api/v1/klines?interval=1M&limit=500&startTime=1519862400000&endTime=1539234000000&symbol=BNBBTC" ,
351+ json = first_res ,
352+ )
353+ klines = client .get_historical_klines_generator (
354+ symbol = "BNBBTC" ,
355+ interval = Client .KLINE_INTERVAL_1MONTH ,
356+ start_str = 1519862400000 ,
357+ end_str = 1539234000000 ,
358+ )
359+
360+ for i in range (8 ):
361+ assert len (next (klines )) > 0
362+
363+ with pytest .raises (StopIteration ):
364+ next (klines )
0 commit comments