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

Method fetch_ohlcv

python/ccxt/alpaca.py:714–802  ·  view source on GitHub ↗

fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market https://docs.alpaca.markets/reference/cryptobars https://docs.alpaca.markets/reference/cryptolatestbars :param str symbol: unified symbol of the market t

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

Source from the content-addressed store, hash-verified

712 return self.parse_order_book(rawOrderbook, market['symbol'], timestamp, 'b', 'a', 'p', 's')
713
714 def fetch_ohlcv(self, symbol: str, timeframe: str = '1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
715 """
716 fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
717
718 https://docs.alpaca.markets/reference/cryptobars
719 https://docs.alpaca.markets/reference/cryptolatestbars
720
721 :param str symbol: unified symbol of the market to fetch OHLCV data for
722 :param str timeframe: the length of time each candle represents
723 :param int [since]: timestamp in ms of the earliest candle to fetch
724 :param int [limit]: the maximum amount of candles to fetch
725 :param dict [params]: extra parameters specific to the alpha api endpoint
726 :param str [params.loc]: crypto location, default: us
727 :param str [params.method]: method, default: marketPublicGetV1beta3CryptoLocBars
728 :returns int[][]: A list of candles ordered, open, high, low, close, volume
729 """
730 self.load_markets()
731 market = self.market(symbol)
732 marketId = market['id']
733 loc = self.safe_string(params, 'loc', 'us')
734 method = self.safe_string(params, 'method', 'marketPublicGetV1beta3CryptoLocBars')
735 request = {
736 'symbols': marketId,
737 'loc': loc,
738 }
739 params = self.omit(params, ['loc', 'method'])
740 ohlcvs = None
741 if method == 'marketPublicGetV1beta3CryptoLocBars':
742 if limit is not None:
743 request['limit'] = limit
744 if since is not None:
745 request['start'] = self.yyyymmdd(since)
746 request['timeframe'] = self.safe_string(self.timeframes, timeframe, timeframe)
747 response = self.marketPublicGetV1beta3CryptoLocBars(self.extend(request, params))
748 #
749 # {
750 # "bars": {
751 # "BTC/USD": [
752 # {
753 # "c": 22887,
754 # "h": 22888,
755 # "l": 22873,
756 # "n": 11,
757 # "o": 22883,
758 # "t": "2022-07-21T05:00:00Z",
759 # "v": 1.1138,
760 # "vw": 22883.0155324116
761 # },
762 # {
763 # "c": 22895,
764 # "h": 22895,
765 # "l": 22884,
766 # "n": 6,
767 # "o": 22884,
768 # "t": "2022-07-21T05:01:00Z",
769 # "v": 0.001,
770 # "vw": 22889.5
771 # }

Callers

nothing calls this directly

Calls 12

NotSupportedClass · 0.90
safe_stringMethod · 0.80
safe_dictMethod · 0.80
safe_listMethod · 0.80
load_marketsMethod · 0.45
marketMethod · 0.45
omitMethod · 0.45
yyyymmddMethod · 0.45
extendMethod · 0.45
parse_ohlcvsMethod · 0.45

Tested by

no test coverage detected