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

Method fetch_ohlcv

python/ccxt/cex.py:747–806  ·  view source on GitHub ↗

fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market https://trade.cex.io/docs/#rest-public-api-calls-candles :param str symbol: unified symbol of the market to fetch OHLCV data for :param str timeframe: th

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

Source from the content-addressed store, hash-verified

745 return self.parse_order_book(orderBook, market['symbol'], timestamp)
746
747 def fetch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
748 """
749 fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
750
751 https://trade.cex.io/docs/#rest-public-api-calls-candles
752
753 :param str symbol: unified symbol of the market to fetch OHLCV data for
754 :param str timeframe: the length of time each candle represents
755 :param int [since]: timestamp in ms of the earliest candle to fetch
756 :param int [limit]: the maximum amount of candles to fetch
757 :param dict [params]: extra parameters specific to the exchange API endpoint
758 :param int [params.until]: timestamp in ms of the latest entry
759 :returns int[][]: A list of candles ordered, open, high, low, close, volume
760 """
761 dataType = None
762 dataType, params = self.handle_option_and_params(params, 'fetchOHLCV', 'dataType')
763 if dataType is None:
764 raise ArgumentsRequired(self.id + ' fetchOHLCV requires a parameter "dataType" to be either "bestBid" or "bestAsk"')
765 self.load_markets()
766 market = self.market(symbol)
767 request = {
768 'pair': market['id'],
769 'resolution': self.timeframes[timeframe],
770 'dataType': dataType,
771 }
772 if since is not None:
773 request['fromISO'] = self.iso8601(since)
774 until = None
775 until, params = self.handle_param_integer_2(params, 'until', 'till')
776 if until is not None:
777 request['toISO'] = self.iso8601(until)
778 elif since is None:
779 # exchange still requires that we provide one of them
780 request['toISO'] = self.iso8601(self.milliseconds())
781 if since is not None and until is not None and limit is not None:
782 raise ArgumentsRequired(self.id + ' fetchOHLCV does not support fetching candles with both a limit and since/until')
783 elif (since is not None or until is not None) and limit is None:
784 raise ArgumentsRequired(self.id + ' fetchOHLCV requires a limit parameter when fetching candles with since or until')
785 if limit is not None:
786 request['limit'] = limit
787 response = self.publicPostGetCandles(self.extend(request, params))
788 #
789 # {
790 # "ok": "ok",
791 # "data": [
792 # {
793 # "timestamp": "1728643320000",
794 # "open": "61061",
795 # "high": "61095.1",
796 # "low": "61048.5",
797 # "close": "61087.8",
798 # "volume": "0",
799 # "resolution": "1m",
800 # "isClosed": True,
801 # "timestampISO": "2024-10-11T10:42:00.000Z"
802 # },
803 # ...
804 #

Callers

nothing calls this directly

Calls 11

ArgumentsRequiredClass · 0.90
safe_listMethod · 0.80
publicPostGetCandlesMethod · 0.65
load_marketsMethod · 0.45
marketMethod · 0.45
iso8601Method · 0.45
millisecondsMethod · 0.45
extendMethod · 0.45
parse_ohlcvsMethod · 0.45

Tested by

no test coverage detected