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

Method fetch_ohlcv

python/ccxt/delta.py:1580–1633  ·  view source on GitHub ↗

fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market https://docs.delta.exchange/#delta-exchange-api-v2-historical-ohlc-candles-sparklines :param str symbol: unified symbol of the market to fetch OHLCV data for

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

Source from the content-addressed store, hash-verified

1578 ]
1579
1580 def fetch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
1581 """
1582 fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1583
1584 https://docs.delta.exchange/#delta-exchange-api-v2-historical-ohlc-candles-sparklines
1585
1586 :param str symbol: unified symbol of the market to fetch OHLCV data for
1587 :param str timeframe: the length of time each candle represents
1588 :param int [since]: timestamp in ms of the earliest candle to fetch
1589 :param int [limit]: the maximum amount of candles to fetch
1590 :param dict [params]: extra parameters specific to the exchange API endpoint
1591 :param str [params.until]: timestamp in ms of the latest candle to fetch
1592 :returns int[][]: A list of candles ordered, open, high, low, close, volume
1593 """
1594 self.load_markets()
1595 market = self.market(symbol)
1596 request = {
1597 'resolution': self.safe_string(self.timeframes, timeframe, timeframe),
1598 }
1599 duration = self.parse_timeframe(timeframe)
1600 limit = limit if limit else 2000 # max 2000
1601 until = self.safe_integer_product(params, 'until', 0.001)
1602 untilIsDefined = (until is not None)
1603 if untilIsDefined:
1604 until = self.parse_to_int(until)
1605 if since is None:
1606 end = until if untilIsDefined else self.seconds()
1607 request['end'] = end
1608 request['start'] = end - limit * duration
1609 else:
1610 start = self.parse_to_int(since / 1000)
1611 request['start'] = start
1612 request['end'] = until if untilIsDefined else self.sum(start, limit * duration)
1613 price = self.safe_string(params, 'price')
1614 if price == 'mark':
1615 request['symbol'] = 'MARK:' + market['id']
1616 elif price == 'index':
1617 request['symbol'] = market['info']['spot_index']['symbol']
1618 else:
1619 request['symbol'] = market['id']
1620 params = self.omit(params, ['price', 'until'])
1621 response = self.publicGetHistoryCandles(self.extend(request, params))
1622 #
1623 # {
1624 # "success":true,
1625 # "result":[
1626 # {"time":1605393120,"open":15989,"high":15989,"low":15987.5,"close":15987.5,"volume":565},
1627 # {"time":1605393180,"open":15966,"high":15966,"low":15959,"close":15959,"volume":24},
1628 # {"time":1605393300,"open":15973,"high":15973,"low":15973,"close":15973,"volume":1288},
1629 # ]
1630 # }
1631 #
1632 result = self.safe_list(response, 'result', [])
1633 return self.parse_ohlcvs(result, market, timeframe, since, limit)
1634
1635 def parse_balance(self, response) -> Balances:
1636 balances = self.safe_list(response, 'result', [])

Callers

nothing calls this directly

Calls 13

load_marketsMethod · 0.95
safe_stringMethod · 0.80
parse_timeframeMethod · 0.80
safe_integer_productMethod · 0.80
parse_to_intMethod · 0.80
safe_listMethod · 0.80
marketMethod · 0.45
secondsMethod · 0.45
sumMethod · 0.45
omitMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected