示例#1
0
    async def _every_currency(self,
                              currencies=None,
                              start=None,
                              end=None,
                              use_auto_timeframe=False,
                              consumers=None):
        """Returns graphs data from every currency in
        coinmarketcap passing a list of currencies as
        first parameter. As default returns graphs data
        for all currencies.

        Args:
            currencies (list, optional): Iterator with all
                the currencies that you want to retrieve.
                As default ``None`` (:meth:`pymarketcap.Pymarketcap.coins`
                will be used in that case).
            start (datetime, optional): Time to start retrieving
                graphs data in datetime. As default ``None``.
            end (datetime, optional): Time to end retrieving
                graphs data in datetime. As default ``None``.
            use_auto_timeframe (bool, optional): Use auto time frames same
                as fronted API. As default ``False``
            consumers (int, optional): Number of consumers
                processing the requests simultaneously.
                As default ``None``
                (see :attr:`pymarketcap.AsyncPymarketcap.consumers`).

        Returns (async iterator): Graphs data from all currencies.
        """
        url_kwargs = {}
        if use_auto_timeframe:
            url_kwargs.update(
                start=start,
                end=end,
            )

        if currencies is None:
            currencies = [
                curr["website_slug"] for curr in self.sync.cryptocurrencies
            ]

        res = await self._async_multiget(
            currencies,
            partial(self._base_graphs_currency_url, **url_kwargs),
            consumers if consumers else self.consumers,
            desc="Retrieving all graphs data for %d currencies "
            "from coinmarketcap" % len(currencies))
        for url, raw_res in res:
            self.logger.debug("Processing data from %s" % url)
            raw_res = loads(raw_res)
            response = processer.graphs(raw_res, start, end)
            response.update(
                self.sync.cryptocurrency_by_field_value(
                    "website_slug",
                    url.split("/")[4]))
            yield response
示例#2
0
    async def _every_currency(self,
                              currencies=None,
                              start=None,
                              end=None,
                              consumers=None):
        """Returns graphs data from every currency in
        coinmarketcap passing a list of currencies as
        first parameter. As default returns graphs data
        for all currencies.

        Args:
            currencies (list, optional): Iterator with all
                the currencies that you want to retrieve.
                As default ``None`` (``self.coins`` will
                be used in that case).
            start (datetime, optional): Time to start retrieving
                graphs data in datetime. As default ``None``.
            end (datetime, optional): Time to end retrieving
                graphs data in datetime. As default ``None``.
            consumers (int, optional): Number of consumers
                processing the requests simultaneously.
                As default ``None`` (``self.consumers``).

        Returns (async iterator): Graphs data from all currencies.
        """
        currencies = currencies if currencies else self.coins
        res = await self._async_multiget(
            currencies,
            self._base_graphs_currency_url,
            consumers if consumers else self.consumers,
            desc="Retrieving all graphs data " \
                 + "for %d currencies from coinmarketcap" % len(currencies)
        )
        for url, raw_res in res:
            try:
                raw_res = loads(raw_res)
            except JSONDecodeError:  # Ignore 404 responses
                continue
            response = processer.graphs(raw_res, start, end)
            response["slug"] = url.split("/")[-1]
            for symbol, slug in self.correspondences.items():
                if slug == response["slug"]:
                    response["symbol"] = symbol
                    break
            yield response
示例#3
0
 async def _dominance(self, start=None, end=None):
     url = "https://graphs2.coinmarketcap.com/global/dominance/"
     return processer.graphs(loads(self._get(url)), start, end)
示例#4
0
 async def _global_cap(self, bitcoin=True, start=None, end=None):
     if bitcoin:
         url = "https://graphs2.coinmarketcap.com/global/marketcap-total/"
     else:
         url = "https://graphs2.coinmarketcap.com/global/marketcap-altcoin/"
     return processer.graphs(loads(self._get(url)), start, end)
示例#5
0
 async def _currency(self, name, start=None, end=None):
     res = await self._get(self._base_graphs_currency_url(name))
     return processer.graphs(loads(res), start, end)