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

Method fetch_ohlcv

python/ccxt/bybit.py:2671–2772  ·  view source on GitHub ↗

fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market https://bybit-exchange.github.io/docs/v5/market/kline https://bybit-exchange.github.io/docs/v5/market/mark-kline https://bybit-exchange.github.io/docs/v5/

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

Source from the content-addressed store, hash-verified

2669 ]
2670
2671 def fetch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
2672 """
2673 fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
2674
2675 https://bybit-exchange.github.io/docs/v5/market/kline
2676 https://bybit-exchange.github.io/docs/v5/market/mark-kline
2677 https://bybit-exchange.github.io/docs/v5/market/index-kline
2678 https://bybit-exchange.github.io/docs/v5/market/preimum-index-kline
2679
2680 :param str symbol: unified symbol of the market to fetch OHLCV data for
2681 :param str timeframe: the length of time each candle represents
2682 :param int [since]: timestamp in ms of the earliest candle to fetch
2683 :param int [limit]: the maximum amount of candles to fetch
2684 :param dict [params]: extra parameters specific to the exchange API endpoint
2685 :param int [params.until]: the latest time in ms to fetch orders for
2686 :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)
2687 :returns int[][]: A list of candles ordered, open, high, low, close, volume
2688 """
2689 if symbol is None:
2690 raise ArgumentsRequired(self.id + ' fetchOHLCV() requires a symbol argument')
2691 self.load_markets()
2692 paginate = False
2693 paginate, params = self.handle_option_and_params(params, 'fetchOHLCV', 'paginate')
2694 if paginate:
2695 return self.fetch_paginated_call_deterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 1000)
2696 market = self.market(symbol)
2697 request = {
2698 'symbol': market['id'],
2699 }
2700 if limit is None:
2701 limit = 200 # default is 200 when requested with `since`
2702 if since is not None:
2703 request['start'] = since
2704 if limit is not None:
2705 request['limit'] = limit # max 1000, default 1000
2706 request, params = self.handle_until_option('end', request, params)
2707 request['interval'] = self.safe_string(self.timeframes, timeframe, timeframe)
2708 response: dict
2709 if market['spot']:
2710 request['category'] = 'spot'
2711 response = self.publicGetV5MarketKline(self.extend(request, params))
2712 else:
2713 price = self.safe_string(params, 'price')
2714 params = self.omit(params, 'price')
2715 if market['linear']:
2716 request['category'] = 'linear'
2717 elif market['inverse']:
2718 request['category'] = 'inverse'
2719 else:
2720 raise NotSupported(self.id + ' fetchOHLCV() is not supported for option markets')
2721 if price == 'mark':
2722 response = self.publicGetV5MarketMarkPriceKline(self.extend(request, params))
2723 elif price == 'index':
2724 response = self.publicGetV5MarketIndexPriceKline(self.extend(request, params))
2725 elif price == 'premiumIndex':
2726 response = self.publicGetV5MarketPremiumIndexPriceKline(self.extend(request, params))
2727 else:
2728 response = self.publicGetV5MarketKline(self.extend(request, params))

Callers

nothing calls this directly

Calls 15

ArgumentsRequiredClass · 0.90
NotSupportedClass · 0.90
handle_until_optionMethod · 0.80
safe_stringMethod · 0.80
safe_dictMethod · 0.80
safe_listMethod · 0.80
load_marketsMethod · 0.45

Tested by

no test coverage detected