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

Method fetch_ohlcv

python/ccxt/async_support/hyperliquid.py:1388–1444  ·  view source on GitHub ↗

fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#candle-snapshot :param str symbol: unified symbol of the market to fetch OHLCV d

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

Source from the content-addressed store, hash-verified

1386 }, market)
1387
1388 async def fetch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
1389 """
1390 fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1391
1392 https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#candle-snapshot
1393
1394 :param str symbol: unified symbol of the market to fetch OHLCV data for
1395 :param str timeframe: the length of time each candle represents, support '1m', '15m', '1h', '1d'
1396 :param int [since]: timestamp in ms of the earliest candle to fetch
1397 :param int [limit]: the maximum amount of candles to fetch
1398 :param dict [params]: extra parameters specific to the exchange API endpoint
1399 :param int [params.until]: timestamp in ms of the latest candle to fetch
1400 :returns int[][]: A list of candles ordered, open, high, low, close, volume
1401 """
1402 await self.load_markets()
1403 market = self.market(symbol)
1404 until = self.safe_integer(params, 'until', self.milliseconds())
1405 useTail = since is None
1406 originalSince = since
1407 if since is None:
1408 if limit is not None:
1409 # optimization if limit is provided
1410 timeframeInMilliseconds = self.parse_timeframe(timeframe) * 1000
1411 since = self.sum(until, timeframeInMilliseconds * limit * -1)
1412 if since < 0:
1413 since = 0
1414 useTail = False
1415 else:
1416 since = 0
1417 params = self.omit(params, ['until'])
1418 request = {
1419 'type': 'candleSnapshot',
1420 'req': {
1421 'coin': market['baseName'] if market['swap'] else market['id'],
1422 'interval': self.safe_string(self.timeframes, timeframe, timeframe),
1423 'startTime': since,
1424 'endTime': until,
1425 },
1426 }
1427 response = await self.publicPostInfo(self.extend(request, params))
1428 #
1429 # [
1430 # {
1431 # "T": 1704287699999,
1432 # "c": "2226.4",
1433 # "h": "2247.9",
1434 # "i": "15m",
1435 # "l": "2224.6",
1436 # "n": 46,
1437 # "o": "2247.9",
1438 # "s": "ETH",
1439 # "t": 1704286800000,
1440 # "v": "591.6427"
1441 # }
1442 # ]
1443 #
1444 return self.parse_ohlcvs(response, market, timeframe, originalSince, limit, useTail)
1445

Callers

nothing calls this directly

Calls 11

marketMethod · 0.95
safe_integerMethod · 0.80
parse_timeframeMethod · 0.80
safe_stringMethod · 0.80
publicPostInfoMethod · 0.65
load_marketsMethod · 0.45
millisecondsMethod · 0.45
sumMethod · 0.45
omitMethod · 0.45
extendMethod · 0.45
parse_ohlcvsMethod · 0.45

Tested by

no test coverage detected