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

Method fetch_contract_ohlcv

python/ccxt/kucoin.py:3314–3370  ·  view source on GitHub ↗

@ignore helper method for fetchOHLCV https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-klines :param str symbol: unified symbol of the market to fetch OHLCV data for :param str timeframe: the length of time each candle represents :param

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

Source from the content-addressed store, hash-verified

3312 return self.parse_ohlcvs(data, market, timeframe, since, limit)
3313
3314 def fetch_contract_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
3315 """
3316 @ignore
3317 helper method for fetchOHLCV
3318
3319 https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-klines
3320
3321 :param str symbol: unified symbol of the market to fetch OHLCV data for
3322 :param str timeframe: the length of time each candle represents
3323 :param int [since]: timestamp in ms of the earliest candle to fetch
3324 :param int [limit]: the maximum amount of candles to fetch
3325 :param dict [params]: extra parameters specific to the exchange API endpoint
3326 :returns int[][]: A list of candles ordered, open, high, low, close, volume
3327 """
3328 self.load_markets()
3329 maxLimit = 200
3330 paginate = False
3331 paginate, params = self.handle_option_and_params(params, 'fetchOHLCV', 'paginate')
3332 if paginate:
3333 return self.fetch_paginated_call_deterministic('fetchContractOHLCV', symbol, since, limit, timeframe, params, maxLimit)
3334 market = self.market(symbol)
3335 request = {
3336 'symbol': market['id'],
3337 }
3338 timeframeOptions = self.safe_dict(self.options, 'timeframes', {})
3339 swapTimeframes = self.safe_dict(timeframeOptions, 'swap', {})
3340 parsedTimeframe = self.safe_integer(swapTimeframes, timeframe)
3341 if parsedTimeframe is not None:
3342 request['granularity'] = parsedTimeframe
3343 else:
3344 request['granularity'] = timeframe
3345 duration = self.parse_timeframe(timeframe) * 1000
3346 endAt = self.milliseconds() # required param
3347 if since is not None:
3348 request['from'] = since
3349 if limit is None:
3350 # For each query, the system would return at most 200 pieces of data.
3351 # To obtain more data, please page the data by time.
3352 limit = self.safe_integer(self.options, 'fetchOHLCVLimit', maxLimit)
3353 endAt = self.sum(since, limit * duration)
3354 elif limit is not None:
3355 since = endAt - limit * duration
3356 request['from'] = since
3357 request['to'] = endAt
3358 response = self.futuresPublicGetKlineQuery(self.extend(request, params))
3359 #
3360 # {
3361 # "code": "200000",
3362 # "data": [
3363 # [1636459200000, 4779.3, 4792.1, 4768.7, 4770.3, 78051],
3364 # [1636460100000, 4770.25, 4778.55, 4757.55, 4777.25, 80164],
3365 # [1636461000000, 4777.25, 4791.45, 4774.5, 4791.3, 51555]
3366 # ]
3367 # }
3368 #
3369 data = self.safe_list(response, 'data', [])
3370 return self.parse_ohlcvs(data, market, timeframe, since, limit)
3371

Callers 1

fetch_ohlcvMethod · 0.95

Calls 13

safe_dictMethod · 0.80
safe_integerMethod · 0.80
parse_timeframeMethod · 0.80
safe_listMethod · 0.80
load_marketsMethod · 0.45
marketMethod · 0.45
millisecondsMethod · 0.45
sumMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected