core.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:pymarketcap 作者: mondeja 项目源码 文件源码
def markets(self, currency):
        """Get available coinmarketcap markets data.
        It needs a currency as argument.

        Args:
            currency (str): Currency to get market data

        Returns:
            list: markets on wich provided currency is currently tradeable
        """
        if self.is_symbol(currency):
            currency = self.correspondences[currency]

        url = urljoin(self.urls["web"], "currencies/%s/" % currency)
        html = self._html(url)

        response = []
        marks = html.find('tbody').find_all('tr')

        for m in marks:
            _volume_24h = m.find('span', {'class': 'volume'}).getText()
            volume_24h = self.parse_int(sub(r'\D', '', _volume_24h))
            _price = m.find('span', {'class': 'price'}).getText()
            _price = sub(r'\$| |\*|,', '', _price)
            price = self.parse_float(_price)

            _childs, childs = (m.contents, [])
            for c in _childs:
                if c != '\n':
                    childs.append(c)
            for n, c in enumerate(childs):
                nav = c.string
                if n == 1:
                    exchange = str(nav)
                elif n == 2:
                    pair = str(c.getText()).replace('/', self.pair_separator)
                    if pair[-1] == '*':
                        pair = pair.replace(' *', '')
                elif n == 5:
                    percent_volume = self.parse_float(nav.replace('%', ''))
                elif n == 6:
                    updated = nav == "Recently"
            market = {'exchange': exchange, 'pair': pair,
                      '24h_volume_usd': volume_24h,
                      'price_usd': price,
                      'percent_volume': percent_volume,
                      "updated": updated}
            response.append(market)

        return response
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号