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

Method fetch_ohlcv

python/ccxt/coinbase.py:3629–3696  ·  view source on GitHub ↗

fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market https://docs.cdp.coinbase.com/api-reference/advanced-trade-api/rest-api/products/get-product-candles https://docs.cdp.coinbase.com/api-reference/advanced-trade-ap

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

Source from the content-addressed store, hash-verified

3627 return self.fetch_orders_by_status('CANCELLED', symbol, since, limit, params)
3628
3629 def fetch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
3630 """
3631 fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
3632
3633 https://docs.cdp.coinbase.com/api-reference/advanced-trade-api/rest-api/products/get-product-candles
3634 https://docs.cdp.coinbase.com/api-reference/advanced-trade-api/rest-api/public/get-public-product-candles
3635
3636 :param str symbol: unified symbol of the market to fetch OHLCV data for
3637 :param str timeframe: the length of time each candle represents
3638 :param int [since]: timestamp in ms of the earliest candle to fetch
3639 :param int [limit]: the maximum amount of candles to fetch, not used by coinbase
3640 :param dict [params]: extra parameters specific to the exchange API endpoint
3641 :param int [params.until]: the latest time in ms to fetch trades for
3642 :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)
3643 :param boolean [params.usePrivate]: default False, when True will use the private endpoint to fetch the candles
3644 :returns int[][]: A list of candles ordered, open, high, low, close, volume
3645 """
3646 self.load_markets()
3647 maxLimit = 300
3648 limit = maxLimit if (limit is None) else min(limit, maxLimit)
3649 paginate = False
3650 paginate, params = self.handle_option_and_params(params, 'fetchOHLCV', 'paginate', False)
3651 if paginate:
3652 return self.fetch_paginated_call_deterministic('fetchOHLCV', symbol, since, limit, timeframe, params, maxLimit - 1)
3653 market = self.market(symbol)
3654 request = {
3655 'product_id': market['id'],
3656 'granularity': self.safe_string(self.timeframes, timeframe, timeframe),
3657 }
3658 until = self.safe_integer_n(params, ['until', 'end'])
3659 params = self.omit(params, ['until'])
3660 duration = self.parse_timeframe(timeframe)
3661 requestedDuration = limit * duration
3662 sinceString = None
3663 if since is not None:
3664 sinceString = self.number_to_string(self.parse_to_int(since / 1000))
3665 else:
3666 now = str(self.seconds())
3667 sinceString = Precise.string_sub(now, str(requestedDuration))
3668 request['start'] = sinceString
3669 if until is not None:
3670 request['end'] = self.number_to_string(self.parse_to_int(until / 1000))
3671 else:
3672 # 300 candles max
3673 request['end'] = Precise.string_add(sinceString, str(requestedDuration))
3674 response = None
3675 usePrivate = False
3676 usePrivate, params = self.handle_option_and_params(params, 'fetchOHLCV', 'usePrivate', False)
3677 if usePrivate:
3678 response = self.v3PrivateGetBrokerageProductsProductIdCandles(self.extend(request, params))
3679 else:
3680 response = self.v3PublicGetBrokerageMarketProductsProductIdCandles(self.extend(request, params))
3681 #
3682 # {
3683 # "candles": [
3684 # {
3685 # "start": "1673391780",
3686 # "low": "17414.36",

Callers

nothing calls this directly

Calls 15

safe_stringMethod · 0.80
safe_integer_nMethod · 0.80
parse_timeframeMethod · 0.80
parse_to_intMethod · 0.80
string_subMethod · 0.80
string_addMethod · 0.80
safe_listMethod · 0.80
load_marketsMethod · 0.45

Tested by

no test coverage detected