MCPcopy Create free account
hub / github.com/ccxt/ccxt / fetch_ohlcv

Method fetch_ohlcv

python/ccxt/async_support/xt.py:1383–1472  ·  view source on GitHub ↗

fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market https://doc.xt.com/#market4kline https://doc.xt.com/#futures_quotesgetKLine :param str symbol: unified symbol of the market to fetch OHLCV data for

(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={})

Source from the content-addressed store, hash-verified

1381 })
1382
1383 async def fetch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={}):
1384 """
1385 fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1386
1387 https://doc.xt.com/#market4kline
1388 https://doc.xt.com/#futures_quotesgetKLine
1389
1390 :param str symbol: unified symbol of the market to fetch OHLCV data for
1391 :param str timeframe: the length of time each candle represents
1392 :param int [since]: timestamp in ms of the earliest candle to fetch
1393 :param int [limit]: the maximum amount of candles to fetch
1394 :param dict params: extra parameters specific to the xt api endpoint
1395 :param int [params.until]: timestamp in ms of the latest candle to fetch
1396 :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1397 :returns int[][]: A list of candles ordered, open, high, low, close, volume
1398 """
1399 await self.load_markets()
1400 paginate = False
1401 paginate, params = self.handle_option_and_params(params, 'fetchOHLCV', 'paginate', False)
1402 if paginate:
1403 return await self.fetch_paginated_call_deterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 1000)
1404 market = self.market(symbol)
1405 request = {
1406 'symbol': market['id'],
1407 'interval': self.safe_string(self.timeframes, timeframe, timeframe),
1408 }
1409 if since is not None:
1410 request['startTime'] = since
1411 if limit is not None:
1412 if market['spot']:
1413 limit = min(limit, 1000) # spot max limit
1414 else:
1415 limit = min(limit, 1500) # derivatives max limit
1416 request['limit'] = limit
1417 else:
1418 request['limit'] = 1000
1419 until = self.safe_integer(params, 'until')
1420 params = self.omit(params, ['until'])
1421 if until is not None:
1422 request['endTime'] = until
1423 response = None
1424 if market['linear']:
1425 response = await self.publicLinearGetFutureMarketV1PublicQKline(self.extend(request, params))
1426 elif market['inverse']:
1427 response = await self.publicInverseGetFutureMarketV1PublicQKline(self.extend(request, params))
1428 else:
1429 response = await self.publicSpotGetKline(self.extend(request, params))
1430 #
1431 # spot
1432 #
1433 # {
1434 # "rc": 0,
1435 # "mc": "SUCCESS",
1436 # "ma": [],
1437 # "result": [
1438 # {
1439 # "t": 1678167720000,
1440 # "o": "22467.85",

Callers 2

test_fetch_ohlcvFunction · 0.45
test_fetch_ohlcvFunction · 0.45

Calls 13

safe_stringMethod · 0.80
safe_integerMethod · 0.80
safe_valueMethod · 0.80
publicSpotGetKlineMethod · 0.65
load_marketsMethod · 0.45
marketMethod · 0.45
omitMethod · 0.45
extendMethod · 0.45

Tested by 2

test_fetch_ohlcvFunction · 0.36
test_fetch_ohlcvFunction · 0.36