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

Method fetch_ohlcv

python/ccxt/async_support/gate.py:3227–3292  ·  view source on GitHub ↗

fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market https://www.gate.com/docs/developers/apiv4/en/#market-k-line-chart # spot https://www.gate.com/docs/developers/apiv4/en/#futures-market-k-li

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

Source from the content-addressed store, hash-verified

3225 return returnResult
3226
3227 async def fetch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
3228 """
3229 fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
3230
3231 https://www.gate.com/docs/developers/apiv4/en/#market-k-line-chart # spot
3232 https://www.gate.com/docs/developers/apiv4/en/#futures-market-k-line-chart # swap
3233 https://www.gate.com/docs/developers/apiv4/en/#futures-market-k-line-chart-2 # future
3234 https://www.gate.com/docs/developers/apiv4/en/#options-contract-market-candlestick-chart # option
3235
3236 :param str symbol: unified symbol of the market to fetch OHLCV data for
3237 :param str timeframe: the length of time each candle represents
3238 :param int [since]: timestamp in ms of the earliest candle to fetch
3239 :param int [limit]: the maximum amount of candles to fetch, limit is conflicted with since and params["until"], If either since and params["until"] is specified, request will be rejected
3240 :param dict [params]: extra parameters specific to the exchange API endpoint
3241 :param str [params.price]: "mark" or "index" for mark price and index price candles
3242 :param int [params.until]: timestamp in ms of the latest candle to fetch
3243 :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
3244 :returns int[][]: A list of candles ordered, open, high, low, close, volume(units in quote currency)
3245 """
3246 await self.load_markets()
3247 market = self.market(symbol)
3248 paginate = False
3249 paginate, params = self.handle_option_and_params(params, 'fetchOHLCV', 'paginate')
3250 if paginate:
3251 return await self.fetch_paginated_call_deterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 1000)
3252 if market['option']:
3253 return await self.fetch_option_ohlcv(symbol, timeframe, since, limit, params)
3254 price = self.safe_string(params, 'price')
3255 request = {}
3256 request, params = self.prepare_request(market, None, params)
3257 request['interval'] = self.safe_string(self.timeframes, timeframe, timeframe)
3258 maxLimit = 1999 if market['contract'] else 1000
3259 limit = maxLimit if (limit is None) else min(limit, maxLimit)
3260 until = self.safe_integer(params, 'until')
3261 if until is not None:
3262 until = self.parse_to_int(until / 1000)
3263 params = self.omit(params, 'until')
3264 if since is not None:
3265 duration = self.parse_timeframe(timeframe)
3266 request['from'] = self.parse_to_int(since / 1000)
3267 distance = (limit - 1) * duration
3268 toTimestamp = self.sum(request['from'], distance)
3269 currentTimestamp = self.seconds()
3270 to = min(toTimestamp, currentTimestamp)
3271 if until is not None:
3272 request['to'] = min(to, until)
3273 else:
3274 request['to'] = to
3275 else:
3276 if until is not None:
3277 request['to'] = until
3278 request['limit'] = limit
3279 response = None
3280 if market['contract']:
3281 isMark = (price == 'mark')
3282 isIndex = (price == 'index')
3283 if isMark or isIndex:
3284 request['contract'] = price + '_' + market['id']

Callers

nothing calls this directly

Calls 15

fetch_option_ohlcvMethod · 0.95
prepare_requestMethod · 0.95
safe_stringMethod · 0.80
safe_integerMethod · 0.80
parse_to_intMethod · 0.80
parse_timeframeMethod · 0.80
load_marketsMethod · 0.45
marketMethod · 0.45

Tested by

no test coverage detected