33
loading...
This website collects cookies to deliver better user experience
bitcoin
, ethereum
, dogecoin
, shiba-inu
, basic-attention-token
, and if you want more coins you can check the coingecko API coins list here and now you can search using the shortcut F3 and type the name of the coin you require. #!/bin/bash
read -p "Enter the coin name: " coin
read -p "Enter your national currency: " crncy
days=0
#read -p "Enter the number of days before today to get its price: " days
curl -X 'GET' \
'https://api.coingecko.com/api/v3/coins/ethereum/market_chart?vs_currency=usd&days=0' \
-H 'accept: application/json'
curl -o temp.json -X 'GET' \
'https://api.coingecko.com/api/v3/coins/'$coin'/market_chart?vs_currency='$crncy'&days='$days'' \
-H 'accept: application/json' &> /dev/null
'$variable'
in between the URL to embed the variable value in it. We change the ethereum or any coin name with '$coin'
and the currency name with '$crncy'
and the same for the days as well. We have to store the output in the temp.json file, we use -o to output the result in the specified file in the cURL command. It's optional to add &> /dev/null
because it just flushes the output of cURL, it looks neater if we add it. ,
and ]],"market_caps"
right? ,
and ]],"m
.grep -o -P '(?<=,).*(?=]],"m)' temp.json > price.txt
,
and ]],"m
from the temp.json file and storing the output in the price.txt file. As simple to use and we have the current price of the coin in terms of the provided currency in the file price.txt.while read val
do
p=$val
done < price.txt
p
variable. But we are not done yet, because if we see some values of certain coins which have quite low value, it displays in the scientific format. We'll tackle this in the next section.shiba-inu
or baby-doge-coin
or any other coin with less value then a penny. The value is expressed in scientific notation i.e like 1.998e-5
i.e 0.00001998
price=`printf "%.15f" $p`
p
variable with a precision of 15 decimal values, that is enough for any serious small value coin.echo "The value of $coin in $crncy is = $price"
#!/bin/bash
read -p "Enter the coin name : " coin
read -p "Enter your national currency : " crncy
days=0
#read -p "Enter the number of days past today: " days
touch temp.json price.txt
curl -o temp.json -X 'GET' \
'https://api.coingecko.com/api/v3/coins/'$coin'/market_chart?vs_currency='$crncy'&days='$days'' \
-H 'accept: application/json' &> /dev/null
grep -o -P '(?<=,).*(?=]],"m)' temp.json > price.txt
while read val
do
p=$val
done < price.txt
price=`printf "%.15f" $p`
echo "The value of $coin in $crncy is = $price"
rm temp.json
33