Esempio n. 1
0
    def retrieve(self,coinname):
        coinname=coinname.upper()
        coinID,coinSymbol,coinPrice,coin24Perc,coinMarketCap=None,None,None,None,None
        #coinSymbol=None
        url = 'https://api.coinmarketcap.com/v1/ticker/'
        json_format=utils.get_url_data(url).json()

        for coin in json_format:
            if (coin['symbol']==coinname) or (coin['id']==coinname) or (coin['name']==coinname):
                coinID = coin['id']
                coinSymbol = coin['symbol']
                coinPrice = coin['price_usd']
                coin24Perc = coin['percent_change_24h']
                coinMarketCap = coin['market_cap_usd']
        Controller.passCoin(self,coinID,coinSymbol,coinPrice,coin24Perc,coinMarketCap)
Esempio n. 2
0
def download_coin_data_by_id(coin_id, start_date, end_date):
    """
    Download HTML price history for the specified cryptocurrency and time range from CoinMarketCap.

    :param coin_id: coin_id of a cryptocurrency e.g. btc
    :param start_date: date since when to scrape data (in the format of dd-mm-yyyy)
    :param end_date: date to which scrape the data (in the format of dd-mm-yyyy)
    :return: returns html of the webpage having historical data of cryptocurrency for certain duration
    """

    if start_date is None:
        # default start date on coinmarketcap.com
        start_date = '28-4-2013'

    if end_date is None:
        yesterday = datetime.date.today() - datetime.timedelta(1)
        end_date = yesterday.strftime('%d-%m-%Y')

    # coin_id = get_coin_id(coin_code)

    # Format the dates as required for the url.
    start_date = datetime.datetime.strptime(start_date,
                                            '%d-%m-%Y').strftime('%Y%m%d')
    end_date = datetime.datetime.strptime(end_date,
                                          '%d-%m-%Y').strftime('%Y%m%d')

    url = 'https://coinmarketcap.com/currencies/{0}/historical-data/?start={1}&end={2}'.format(
        coin_id, start_date, end_date)

    try:
        html = get_url_data(url).text
        return html
    except Exception as e:
        print("Error fetching price data for {} for interval '{}' and '{}'",
              coin_id, start_date, end_date)

        if hasattr(e, 'message'):
            print('Error message (download_data) :', e.message)
        else:
            print('Error message (download_data) :', e)
Esempio n. 3
0
def get_coin_ids(coin_code):
    """
    This method fetches the name(id) of currency from the given code
    :param coin_code: coin code of a cryptocurrency e.g. btc
    :return: coin-id for the a cryptocurrency on the coinmarketcap.com
    """
    ids = []
    try:
        url = 'https://api.coinmarketcap.com/v1/ticker/?limit=0'

        json_resp = get_url_data(url).json()

        coin_code = coin_code.upper()

        for coin in json_resp:
            if coin['symbol'] == coin_code:
                ids.append(coin['id'])
        if len(ids) == 0:
            raise InvalidCoinCode('This coin code is unavailable on "coinmarketcap.com"')
    except Exception as e:
        raise e
    return ids