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

Method fetch_ohlcv

python/ccxt/async_support/htx.py:3026–3153  ·  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

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

Callers

nothing calls this directly

Tested by

no test coverage detected