CoinGecko API Wrapper in Julia Language - Part 1
Basic Usage
One of the most powerfull crypto API's out there. APIs are simple and easy to use, fully documented at the website.
("CoinGecko API" is a trademark of CoinGecko)
API Information:
Julia API Wrapper Package information:
Pls check my package information at the website for code and documentation.
# Load dependancies
using CoinGeckoAPI;
using Plots;
# check API documentation for more information - we are interested in the /coins/markets function call for this example
# https://www.coingecko.com/en/api/documentation
# call the API, market cap in USD, optional arguments are:
# order: "market_cap_desc"
# per_page: 10
# page: 1
# We are getting only the top 10 market caps
r = get_coins_markets("usd", "order" => "market_cap_desc", "per_page" => "10", "page" => "1");
Now lets look at the output closer:
length(r)
r |> length #or call the same function but with the pipe operator, my preference!
r |> typeof # this is a vector output, with length 10
we can check the first element:
r[1]
Now let us get all the keys and values pairs:
keys(r[1])
values(r[1])
For this example, we are only interested in name and market cap.
We can use the following code to push names and values to vectors for plotting:
Vₙ = [];# name vector
Mc = []; #value vector
for i in 1:length(r)
push!(Vₙ, r[i]["id"]); #get vector with names
push!(Mc, r[i]["market_cap"]); #get vector with market caps
end
bar(Vₙ, Mc, title = "top 10 coins market cap", ylabel="Market cap", xrotation= 45 ) #plot market caps
That's it!