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

Method fetch_ohlcv

python/ccxt/htx.py:3025–3152  ·  view source on GitHub ↗

fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market https://huobiapi.github.io/docs/spot/v1/en/#get-klines-candles https://huobiapi.github.io/docs/dm/v1/en/#get-kline-data https://huobiapi.github.io/docs/co

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

Source from the content-addressed store, hash-verified

3023 ]
3024
3025 def fetch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
3026 """
3027 fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
3028
3029 https://huobiapi.github.io/docs/spot/v1/en/#get-klines-candles
3030 https://huobiapi.github.io/docs/dm/v1/en/#get-kline-data
3031 https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-kline-data
3032 https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-kline-data
3033
3034 :param str symbol: unified symbol of the market to fetch OHLCV data for
3035 :param str timeframe: the length of time each candle represents
3036 :param int [since]: timestamp in ms of the earliest candle to fetch
3037 :param int [limit]: the maximum amount of candles to fetch
3038 :param dict [params]: extra parameters specific to the exchange API endpoint
3039 :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)
3040 :param str [params.useHistoricalEndpointForSpot]: True/false - whether use the historical candles endpoint for spot markets or default klines endpoint
3041 :returns int[][]: A list of candles ordered, open, high, low, close, volume
3042 """
3043 self.load_markets()
3044 paginate = False
3045 paginate, params = self.handle_option_and_params(params, 'fetchOHLCV', 'paginate')
3046 if paginate:
3047 return self.fetch_paginated_call_deterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 1000)
3048 market = self.market(symbol)
3049 request = {
3050 'period': self.safe_string(self.timeframes, timeframe, timeframe),
3051 # 'symbol': market['id'], # spot, future
3052 # 'contract_code': market['id'], # swap
3053 # 'size': 1000, # max 1000 for spot, 2000 for contracts
3054 # 'from': int((since / str(1000))), spot only
3055 # 'to': self.seconds(), spot only
3056 }
3057 priceType = self.safe_string_n(params, ['priceType', 'price'])
3058 params = self.omit(params, ['priceType', 'price'])
3059 until = None
3060 until, params = self.handle_param_integer(params, 'until')
3061 untilSeconds = self.parse_to_int(until / 1000) if (until is not None) else None
3062 if market['contract']:
3063 if limit is not None:
3064 request['size'] = min(limit, 2000) # when using limit: from & to are ignored
3065 # https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-kline-data
3066 else:
3067 limit = 2000 # only used for from/to calculation
3068 if priceType is None:
3069 duration = self.parse_timeframe(timeframe)
3070 calcualtedEnd = None
3071 if since is None:
3072 now = self.seconds()
3073 request['from'] = now - duration * (limit - 1)
3074 calcualtedEnd = now
3075 else:
3076 start = self.parse_to_int(since / 1000)
3077 request['from'] = start
3078 calcualtedEnd = self.sum(start, duration * (limit - 1))
3079 request['to'] = untilSeconds if (untilSeconds is not None) else calcualtedEnd
3080 response = None
3081 if market['future']:
3082 if market['inverse']:

Callers

nothing calls this directly

Tested by

no test coverage detected