def get_coin_twitter_timeline(coin_id: str = "eth-ethereum") -> pd.DataFrame:
    """Get twitter timeline for given coin id. Not more than last 50 tweets [Source: CoinPaprika]

    Parameters
    ----------
    coin_id: str
        id of coin from coinpaprika e.g. Ethereum - > 'eth-ethereum'
    Returns
    -------
    pandas.DataFrame
        Twitter timeline for given coin.
        Columns: date, user_name, status, retweet_count, like_count
    """

    session = PaprikaSession()
    res = session.make_request(
        session.ENDPOINTS["coin_tweeter"].format(coin_id))
    if "error" in res:
        console.print(res)
        return pd.DataFrame()
    if isinstance(res, list) and len(res) == 0:
        return pd.DataFrame()
    df = pd.DataFrame(res)[[
        "date", "user_name", "status", "retweet_count", "like_count"
    ]]

    df = df.applymap(lambda x: "\n".join(textwrap.wrap(x, width=80))
                     if isinstance(x, str) else x)
    df["status"] = df["status"].apply(lambda x: x.replace("  ", ""))
    df["date"] = df["date"].apply(lambda x: x.replace("T", "\n"))
    df["date"] = df["date"].apply(lambda x: x.replace("Z", ""))
    return df
Exemple #2
0
def get_global_market() -> pd.DataFrame:
    """Return data frame with most important global crypto statistics like:
    market_cap_usd, volume_24h_usd, bitcoin_dominance_percentage, cryptocurrencies_number,
    market_cap_ath_value, market_cap_ath_date, volume_24h_ath_value, volume_24h_ath_date,
    market_cap_change_24h, volume_24h_change_24h, last_updated.   [Source: CoinPaprika]

    Returns
    -------
    pandas.DataFrame
        Most important global crypto statistics
        Metric, Value
    """

    session = PaprikaSession()
    global_markets = session.make_request(session.ENDPOINTS["global"])
    global_markets["last_updated"] = datetime.fromtimestamp(
        global_markets["last_updated"]
    )

    for key, date in global_markets.items():
        if "date" in key:
            try:
                global_markets[key] = parser.parse(date).strftime("%Y-%m-%d %H:%M:%S")
            except (KeyError, ValueError, TypeError) as e:
                console.print(e)
    df = pd.Series(global_markets).to_frame().reset_index()
    df.columns = ["Metric", "Value"]
    return df
Exemple #3
0
def get_list_of_exchanges(quotes: str = "USD") -> pd.DataFrame:
    """
    List exchanges from CoinPaprika API [Source: CoinPaprika]

    Parameters
    ----------
    quotes: str
        Comma separated quotes to return e.g quotes=USD,BTC

    Returns
    -------
    pandas.DataFrame
        rank, name, currencies, markets, fiats, confidence_score, reported_volume_24h,
        reported_volume_7d ,reported_volume_30d, sessions_per_month,
    """

    session = PaprikaSession()
    exchanges = session.make_request(session.ENDPOINTS["exchanges"],
                                     quotes=quotes)
    df = pd.json_normalize(exchanges)
    try:
        df.columns = [
            col.replace(f"quotes.{quotes}.", "")
            for col in df.columns.tolist()
        ]
    except KeyError as e:
        logger.exception(str(e))
        console.print(e)
    df = df[df["active"]]
    cols = [
        "adjusted_rank",
        "id",
        "name",
        "currencies",
        "markets",
        "fiats",
        "confidence_score",
        "reported_volume_24h",
        "reported_volume_7d",
        "reported_volume_30d",
        "sessions_per_month",
    ]
    df.loc[:, "fiats"] = df["fiats"].apply(
        lambda x: len([i["symbol"] for i in x if x]))
    df = df[cols]
    df = df.applymap(lambda x: "\n".join(textwrap.wrap(x, width=28))
                     if isinstance(x, str) else x)
    df.rename(
        columns={
            "adjusted_rank": "rank",
            "confidence_score": "confidence"
        },
        inplace=True,
    )
    df.columns = [x.replace("reported_", "") for x in df.columns]
    return df.sort_values(by="rank")
def get_coin(coin_id="eth-ethereum"):
    """Get coin by id
    Parameters
    ----------
    coin_id: str
        id of coin from coinpaprika e.g. Ethereum - > 'eth-ethereum'
    Returns
    -------
    dict with response
    """
    session = PaprikaSession()
    coin = session.make_request(session.ENDPOINTS["coin"].format(coin_id))
    return coin
Exemple #5
0
def get_list_of_coins() -> pd.DataFrame:
    """Get list of all available coins on CoinPaprika  [Source: CoinPaprika]

    Returns
    -------
    pandas.DataFrame
        Available coins on CoinPaprika
        rank, id, name, symbol, type
    """

    session = PaprikaSession()
    coins = session.make_request(session.ENDPOINTS["coins"])
    df = pd.DataFrame(coins)
    df = df[df["is_active"]]
    return df[["rank", "id", "name", "symbol", "type"]]
Exemple #6
0
def get_all_contract_platforms() -> pd.DataFrame:
    """List all smart contract platforms like ethereum, solana, cosmos, polkadot, kusama ... [Source: CoinPaprika]

    Returns
    -------
    pandas.DataFrame
        index, platform_id
    """

    session = PaprikaSession()
    contract_platforms = session.make_request(
        session.ENDPOINTS["contract_platforms"])
    df = pd.DataFrame(contract_platforms).reset_index()
    df.columns = ["index", "platform_id"]
    df["index"] = df["index"] + 1
    return df
def get_coin_events_by_id(coin_id: str = "eth-ethereum") -> pd.DataFrame:
    """Get all events related to given coin like conferences, start date of futures trading etc. [Source: CoinPaprika]

    Example of response from API:

    .. code-block:: json

        {
            "id": "17398-cme-april-first-trade",
            "date": "2018-04-02T00:00:00Z",
            "date_to": "string",
            "name": "CME: April First Trade",
            "description": "First trade of Bitcoin futures contract for April 2018.",
            "is_conference": false,
            "link": "http://www.cmegroup.com/trading/equity-index/us-index/bitcoin_product_calendar_futures.html",
            "proof_image_link": "https://static.coinpaprika.com/storage/cdn/event_images/16635.jpg"
        }

    .

    Parameters
    ----------
    coin_id: str
        id of coin from coinpaprika e.g. Ethereum - > 'eth-ethereum'
    Returns
    -------
    pandas.DataFrame
        Events found for given coin
        Columns: id, date , date_to, name, description, is_conference, link, proof_image_link
    """

    session = PaprikaSession()
    res = session.make_request(
        session.ENDPOINTS["coin_events"].format(coin_id))
    if not res or "error" in res:
        return pd.DataFrame()
    data = pd.DataFrame(res)
    data["description"] = data["description"].apply(lambda x: "\n".join(
        textwrap.wrap(x, width=40)) if isinstance(x, str) else x)
    data.drop(["id", "proof_image_link"], axis=1, inplace=True)
    for col in ["date", "date_to"]:
        data[col] = data[col].apply(lambda x: x.replace("T", "\n")
                                    if isinstance(x, str) else x)
        data[col] = data[col].apply(lambda x: x.replace("Z", "")
                                    if isinstance(x, str) else x)
    return data
Exemple #8
0
def get_contract_platform(platform_id: str = "eth-ethereum") -> pd.DataFrame:
    """Gets all contract addresses for given platform [Source: CoinPaprika]
    Parameters
    ----------
    platform_id: str
        Blockchain platform like eth-ethereum

    Returns
    -------
    pandas.DataFrame
         id, type, active
    """

    session = PaprikaSession()
    contract_platforms = session.make_request(
        session.ENDPOINTS["contract_platform_addresses"].format(platform_id))

    return pd.DataFrame(contract_platforms)[["id", "type", "active"]]
def get_ohlc_historical(coin_id: str = "eth-ethereum",
                        quotes: str = "USD",
                        days: int = 90) -> pd.DataFrame:
    """
    Open/High/Low/Close values with volume and market_cap. [Source: CoinPaprika]
    Request example: https://api.coinpaprika.com/v1/coins/btc-bitcoin/ohlcv/historical?start=2019-01-01&end=2019-01-20
    if the last day is current day it can an change with every request until actual close of the day at 23:59:59


    Parameters
    ----------
    coin_id: str
        Paprika coin identifier e.g. eth-ethereum
    quotes: str
        returned data quote (available values: usd btc)
    days: int
        time range for chart in days. Maximum 365

    Returns
    -------
    pandas.DataFrame
        Open/High/Low/Close values with volume and market_cap.
    """

    if quotes.lower() not in ["usd", "btc"]:
        quotes = "USD"

    if abs(int(days)) > 365:
        days = 365

    end = datetime.now().strftime("%Y-%m-%d")
    start = (datetime.now() - timedelta(days=days)).strftime("%Y-%m-%d")

    session = PaprikaSession()
    data = session.make_request(
        session.ENDPOINTS["ohlcv_hist"].format(coin_id),
        quotes=quotes,
        start=start,
        end=end,
    )
    if "error" in data:
        console.print(data)
        return pd.DataFrame()
    return pd.DataFrame(data)
def get_coin_markets_by_id(coin_id: str = "eth-ethereum",
                           quotes: str = "USD") -> pd.DataFrame:
    """All markets for given coin and currency [Source: CoinPaprika]

    Parameters
    ----------
    coin_id: str
        Coin Parpika identifier of coin e.g. eth-ethereum
    quotes: str
        Comma separated list of quotes to return.
        Example: quotes=USD,BTC
        Allowed values:
        BTC, ETH, USD, EUR, PLN, KRW, GBP, CAD, JPY, RUB, TRY, NZD, AUD, CHF, UAH, HKD, SGD, NGN, PHP, MXN, BRL,
        THB, CLP, CNY, CZK, DKK, HUF, IDR, ILS, INR, MYR, NOK, PKR, SEK, TWD, ZAR, VND, BOB, COP, PEN, ARS, ISK

    Returns
    -------
    pandas.DataFrame
        All markets for given coin and currency
    """

    session = PaprikaSession()
    markets = session.make_request(
        session.ENDPOINTS["coin_markets"].format(coin_id), quotes=quotes)
    if "error" in markets:
        console.print(markets)
        return pd.DataFrame()

    data = []
    for r in markets:
        dct = {
            "exchange": r.get("exchange_name"),
            "pair": r.get("pair"),
            "trust_score": r.get("trust_score"),
            "pct_volume_share": r.get("adjusted_volume_24h_share"),
        }
        _quotes: dict = r.get("quotes")
        for k, v in _quotes.items():
            dct[f"{k.lower()}_price"] = v.get("price")
            dct[f"{k.lower()}_volume"] = v.get("volume_24h")
        dct["market_url"] = r.get("market_url")
        data.append(dct)

    return pd.DataFrame(data)
def get_coin_exchanges_by_id(coin_id="eth-ethereum"):
    """Get all exchanges for given coin id.

    Parameters
    ----------
    coin_id: Identifier of Coin from CoinPaprika

    Returns
    -------
    pandas.DataFrame
        id, name, adjusted_volume_24h_share, fiats
    """
    session = PaprikaSession()
    res = session.make_request(
        session.ENDPOINTS["coin_exchanges"].format(coin_id))
    df = pd.DataFrame(res)
    df["fiats"] = df["fiats"].copy().apply(
        lambda x: len([i["symbol"] for i in x if x]))
    return df
def get_search_results(query: str,
                       category: Optional[Any] = None,
                       modifier: Optional[Any] = None) -> pd.DataFrame:
    """Search CoinPaprika. [Source: CoinPaprika]

    Parameters
    ----------
    query:  str
        phrase for search
    category:  Optional[Any]
        one or more categories (comma separated) to search.
        Available options: currencies|exchanges|icos|people|tags
        Default: currencies,exchanges,icos,people,tags
    modifier: Optional[Any]
        set modifier for search results. Available options: symbol_search -
        search only by symbol (works for currencies only)

    Returns
    -------
    pandas.DataFrame
        Search Results
        Columns: Metric, Value
    """

    session = PaprikaSession()
    if category is None:
        category = "currencies,exchanges,icos,people,tags"
    data = session.make_request(session.ENDPOINTS["search"],
                                q=query,
                                c=category,
                                modifier=modifier,
                                limit=100)
    results = []
    for item in data:
        category = data[item]
        for r in category:
            results.append({
                "id": r.get("id"),
                "name": r.get("name"),
                "category": item,
            })
    return pd.DataFrame(results)
Exemple #13
0
def get_exchanges_market(
    exchange_id: str = "binance", quotes: str = "USD"
) -> pd.DataFrame:
    """List markets by exchange ID [Source: CoinPaprika]

    Parameters
    ----------
    exchange_id: str
        identifier of exchange e.g for Binance Exchange -> binance
    quotes: str
        Comma separated quotes to return e.g quotes=USD,BTC

    Returns
    -------
    pandas.DataFrame
        pair, base_currency_name, quote_currency_name, market_url,
        category, reported_volume_24h_share, trust_score,
    """

    session = PaprikaSession()
    data = session.make_request(
        session.ENDPOINTS["exchange_markets"].format(exchange_id), quotes=quotes
    )
    if "error" in data:
        console.print(data)
        return pd.DataFrame()
    cols = [
        "exchange_id",
        "pair",
        "base_currency_name",
        "quote_currency_name",
        "category",
        "reported_volume_24h_share",
        "trust_score",
        "market_url",
    ]
    df = pd.DataFrame(data)
    df["exchange_id"] = exchange_id
    return df[cols]
def get_tickers_info_for_coin(coin_id: str = "btc-bitcoin",
                              quotes: str = "USD") -> pd.DataFrame:
    """Get all most important ticker related information for given coin id [Source: CoinPaprika]

    .. code-block:: json

        {
            "id": "btc-bitcoin",
            "name": "Bitcoin",
            "symbol": "BTC",
            "rank": 1,
            "circulating_supply": 17007062,
            "total_supply": 17007062,
            "max_supply": 21000000,
            "beta_value": 0.735327,
            "first_data_at": "2010-11-14T07:20:41Z",
            "last_updated": "2018-11-14T07:20:41Z",
            "quotes": {
                "USD": {
                    "price": 5162.15941296,
                    "volume_24h": 7304207651.1585,
                    "volume_24h_change_24h": -2.5,
                    "market_cap": 91094433242,
                    "market_cap_change_24h": 1.6,
                    "percent_change_15m": 0,
                    "percent_change_30m": 0,
                    "percent_change_1h": 0,
                    "percent_change_6h": 0,
                    "percent_change_12h": -0.09,
                    "percent_change_24h": 1.59,
                    "percent_change_7d": 0.28,
                    "percent_change_30d": 27.39,
                    "percent_change_1y": -37.99,
                    "ath_price": 20089,
                    "ath_date": "2017-12-17T12:19:00Z",
                    "percent_from_price_ath": -74.3
                }
            }
        }

    Parameters
    ----------
    coin_id: str
        Id of coin from CoinPaprika
    quotes: str
        Comma separated quotes to return e.g quotes = USD, BTC

    Returns
    -------
    pandas.DataFrame
        Most important ticker related information
        Columns: Metric, Value
    """

    session = PaprikaSession()
    tickers = session.make_request(
        session.ENDPOINTS["ticker_info"].format(coin_id), quotes=quotes)

    for key, date in tickers.items():
        if "date" in key or "data" in key:
            try:
                tickers[key] = parser.parse(date).strftime("%Y-%m-%d %H:%M:%S")
            except (KeyError, ValueError, TypeError) as e:
                logger.exception(str(e))
                console.print(e)
        if key == "quotes":
            try:
                tickers[key][quotes]["ath_date"] = parser.parse(
                    tickers[key][quotes]["ath_date"]).strftime(
                        "%Y-%m-%d %H:%M:%S")
            except (KeyError, ValueError, TypeError) as e:
                logger.exception(str(e))
                console.print(e)

    df = pd.json_normalize(tickers)
    try:
        df.columns = [col.replace("quotes.", "") for col in list(df.columns)]
        df.columns = [
            col.replace(".", "_").lower() for col in list(df.columns)
        ]
    except KeyError as e:
        logger.exception(str(e))
        console.print(e)
    df = df.T.reset_index()
    df.columns = ["Metric", "Value"]
    return df
Exemple #15
0
def _get_coins_info_helper(quotes: str = "USD") -> pd.DataFrame:
    """Helper method that call /tickers endpoint which returns for all coins quoted in provided currency/crypto

    {
        "id": "btc-bitcoin",
        "name": "Bitcoin",
        "symbol": "BTC",
        "rank": 1,
        "circulating_supply": 17007062,
        "total_supply": 17007062,
        "max_supply": 21000000,
        "beta_value": 0.735327,
        "first_data_at": "2010-11-14T07:20:41Z",
        "last_updated": "2018-11-14T07:20:41Z",
        "quotes" : {
                "USD": {
                    "price": 5162.15941296,
                    "volume_24h": 7304207651.1585,
                    "volume_24h_change_24h": -2.5,
                    "market_cap": 91094433242,
                    "market_cap_change_24h": 1.6,
                    "percent_change_15m": 0,
                    "percent_change_30m": 0,
                    "percent_change_1h": 0,
                    "percent_change_6h": 0,
                    "percent_change_12h": -0.09,
                    "percent_change_24h": 1.59,
                    "percent_change_7d": 0.28,
                    "percent_change_30d": 27.39,
                    "percent_change_1y": -37.99,
                    "ath_price": 20089,
                    "ath_date": "2017-12-17T12:19:00Z",
                    "percent_from_price_ath": -74.3
                    }
                }
    }

    [Source: CoinPaprika]

    Parameters
    ----------
    quotes: Comma separated quotes to return e.g quotes=USD,BTC

    Returns
    -------
    pandas.DataFrame
        id, name, symbol, rank, circulating_supply, total_supply, max_supply, beta_value, first_data_at,
        last_updated, price, volume_24h, volume_24h_change_24h, market_cap, market_cap_change_24h,
        percent_change_15m, percent_change_30m, percent_change_1h, percent_change_6h, percent_change_12h,
       percent_change_24h, percent_change_7d, percent_change_30d, percent_change_1y,
       ath_price, ath_date, percent_from_price_ath
    """

    session = PaprikaSession()
    tickers = session.make_request(session.ENDPOINTS["tickers"], quotes=quotes)
    data = pd.json_normalize(tickers)
    try:
        # data.columns = [col.replace(f"quotes.{quotes}.", f"{quotes.lower()}_") for col in data.columns.tolist()]
        data.columns = [
            col.replace(f"quotes.{quotes}.", "") for col in data.columns.tolist()
        ]
        data.columns = [col.replace("percent", "pct") for col in list(data.columns)]
    except KeyError as e:
        console.print(e)
    data.rename(
        columns={
            "market_cap_change_24h": "mcap_change_24h",
            "pct_from_price_ath": "pct_from_ath",
        },
        inplace=True,
    )
    return data