To use the CoinGecko API to pull in different types of data related to the criptto curency. Along with pulling in basic market data, I will also be pulling in a full list of all coins that are in Coingecko and have a person pass a filter critera to make the list of coins much shorter.
The API that is used is the free API that is provided by CoinGecko. All of documentation can be found at CoinGecko API. Here is the link to the Github repo that made the API work more seemlessly in python python coingecko API repo.
A lot of the data cleaning was made easy because of the pycoingecko python packages. Most of the data from CoinGeck API would come back in a dictionary. Below are some examples of how the data would come back.
cg.get_price(ids='bitcoin',vs_currencies='usd')
{'bitcoin'
{'usd' : 38258}}
cg.get_price(ids = ['bitcoin','litecoin'],vs_currencies='usd')
{'bitcoin':
{'usd': 38242},
'litecoin':
{'usd': 99.21}}
cg.get_coin_market_chart_by_id(id = 'bitcoin',vs_currency= 'usd',days = 1)
{'prices':
{[1646699541000, 38242.27428142403]},
'market_caps':
{[1646699541000, 725275467246.7909]},
'total_volumes':
{[1646699541000, 24057303397.88596]}}
The above code is returning a dictionary with keys of prices,market_caps,and total_volumnes with each element being a list of values. The first value in the list is a time stamp in the format of "find the format name" and the second value being the value of the dictorny key. The way I would extract infromation for a given key I would run pd.json_normalize(raw_data,record_path = 'prices')
, to convert the time into standered datetime format I would run the following command pd.to_datetime(price_data[0],unit = 'ms')
cg = pycoin.CoinGeckoAPI()
testing_coin_connection(CG)
This will test the API connection to CoinGecko, and will return weather or not the coneection is good.
CG => This is the API key for CoinGecko. A free key can be apptaned by running CoinGeckoAPI()
from the pycoingecko package. For more information please see API seciont of the documentation above.
A string will be returned stating if the connection is good. If a connection is not good it will return a list with the first element being a stirng stateing connection is not good, and the second element being the return value from the testing the API.
cg = pycoin.CoinGeckoAPI()
cryp_list = ['bitcoin', 'tether', 'ethereum','solana','binance coin']
pull_in_top_5_data(CG,cryp_list)
This will return the 5 higest coins on CoinGeko in a table format.
-
CG => This is the API key for CoinGecko. A free key can be apptaned by running
CoinGeckoAPI()
from the pycoingecko package. For more information please see API seciont of the documentation above. -
cryp_list => This is a lit of top 5 current ctypto conins avaiable on CoinGeko.
- This will output a table to the screen showing coin name and the current pirce in US dollars.
cg = pycoin.CoinGeckoAPI()
get_token_list(CG)
The get_token_list function will return all of the current tokens that are avaiable on CoinGeko. It will return a datafrmae that has ID,symbol and the name of the coin.
- CG => This is the API key for CoinGecko. A free key can be apptaned by running
CoinGeckoAPI()
from the pycoingecko package. For more information please see API seciont of the documentation above.
- Returns a dataframe with all of the coins that are avaible on coinGeko. The dataframe has the columns, ID,symbol and name.
cg = pycoin.CoinGeckoAPI()
top_7_table(cg)
- The Top_7_table function returns a table of top seven most search coins on CoinGeko and outputs the table to the standerd out. The table will have the coins ranked value,coin name, Coin ID,coin symbol, market cap, current trading price in Bitoin and current price in US dollars.
- CG => This is the API key for CoinGecko. A free key can be apptaned by running
CoinGeckoAPI()
from the pycoingecko package. For more information please see API seciont of the documentation above.
- Returns a dataframe with all of the top 7 coins being search for on CoinGecko.
- stuff
cg = pycoin.CoinGeckoAPI()
Chart_Analysis(api_key = cg,
days_back = 90,
coin = 'bitcoin',
info = ['Price','Market Cap','Total Volumes'])
- The Chart analysis fucnctions can return upto 3 charts related to any one given coin. That charts that can be returned are price over time, market cap over time and total volume over time.
- api_key => This is the API key for CoinGecko. A free key can be apptaned by running
CoinGeckoAPI()
from the pycoingecko package. For more information please see API seciont of the documentation above. - days_back => How many days back you would like to pull coin information.
- coin => The name of the coin that you want to pull information for.
- info => A list of graphs that you would like to see. The three graphs that can be inputed Price, Market Cap and total volume.