【初心者向け】CoinGecko APIを使って仮想通貨の市場価値を取得してみる

# CoinGeckoとは

https://www.coingecko.com/ja

CoinGeckoは、仮想通貨市場の情報を提供するウェブサイトです。
さらに!!
仮想通貨情報や、トレンド、トランザクション等を取得できるAPIを無料[一部有料]で提供しています。


# ハンズオン
今回はCoinGeckoはのAPIを使って、仮想通貨の市場価格を取得するコードを書いてみます!!

## 公式ドキュメント

https://www.coingecko.com/ja/api/documentation

まずは公式ドキュメントから行きます。
公式ドキュメントには、Swagger UIで実際にAPIを試せるようになっています。(ありがたい)
今回使用する、エンドポイントは`/coins`を使用します。
![スクリーンショット 2023-07-08 21.35.39.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/433195/f562396c-c590-c28e-8369-7f94ef9666b7.png)

本ハンズオンでは最近僕が購入した(すぐに下落しました)リップルの情報を取得しようと思います。
`[GET]/coins/list`からリップルを探してもいいんですけど、面倒くさいんで普通に検索しちゃいます。

## 公式ページ
「CoinGecko リップル」みたいな感じで検索してください。
リップル以外にも有名所はだいたい揃っているので、好きなものを検索してみてください。
![スクリーンショット 2023-07-08 21.44.19.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/433195/eb1d16d8-5969-4ef2-fe9f-d491accb30f6.png)

こちらがページになります。
現在の市場価格がガッツリ書いてあるんですけど、目を塞いで、
右下の`API ID`を利用したいのでコピーしてください。

## コーディング
僕はGoを使いますが、お好きな言語を使ってください。

今回は現在の市場価値を取得したいので
`[GET] /coins/{id}`を使用します。

クエリパラメータに色々設定できるので、`merket_data`だけ取得するようにします。

![スクリーンショット 2023-07-09 12.27.08.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/433195/486a2c3c-e473-a23b-e4ad-a31d22235875.png)

### とりあえず叩いてみる
サクッと作りました。

```go:main.go
package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	apiID := "axie-infinity"

	url := `https://api.coingecko.com/api/v3/coins/` + apiID + `?localization=false&tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false`

	resp, err := http.Get(url)
	if err != nil {
		fmt.Printf("Request Error : %s\n", err)
		return
	}

	defer func(Body io.ReadCloser) {
		err := Body.Close()
		if err != nil {

		}
	}(resp.Body)

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		fmt.Printf("Response Error : %s\n", err)
		return
	}

	fmt.Println(string(body))
}
```

urlを叩いて、取得結果を出力しています。

```json:出力結果
{"id":"axie-infinity","symbol":"axs","name":"Axie Infinity","asset_platform_id":"ethereum","platforms":{"ethereum":"0xbb0e17ef65f82ab018d8edd776e8dd940327b28b","binance-smart-chain":"0x715d400f88c167884bbcc41c5fea407ed4d2f8a0","harmony-shard-0":"0x14a7b318fed66ffdcc80c1517c172c13852865de","ronin":"0x97a9107c1793bc407d6f527b77e7fff4d812bece","energi":"0x7cd3d51bee45434dd80822c5d58b999333b69ffb"},"detail_platforms":{"ethereum":{"decimal_place":18,"contract_address":"0xbb0e17ef65f82ab018d8edd776e8dd940327b28b"},"binance-smart-chain":{"decimal_place":18,"contract_address":"0x715d400f88c167884bbcc41c5fea407ed4d2f8a0"},"harmony-shard-0":{"decimal_place":18,"contract_address":"0x14a7b318fed66ffdcc80c1517c172c13852865de"},"ronin":{"decimal_place":18,"contract_address":"0x97a9107c1793bc407d6f527b77e7fff4d812bece"},"energi":{"decimal_place":18,"contract_address":"0x7cd3d51bee45434dd80822c5d58b999333b69ffb"}},"block_time_in_minutes":0,"hashing_algorithm":null,"categories":["Harmony Ecosystem","Ethereum Ecosystem","BNB Chain Ecosystem","Metaverse","Play To Earn","Gaming (GameFi)","Axie Infinity","NFT"],"public_notice":null,"additional_notices":[],"description":{"en":"AXS is the governance token for the Axie Infinity game. Token holders will be able to shape and vote for the direction of the game universe. This is unlike traditional games where all decisions are made by the game developers. AXS holders will be able to stake their tokens to earn more AXS and even vote for governance proposals."},"links":{"homepage":["https://axieinfinity.com/","",""],"blockchain_site":["https://etherscan.io/token/0xbb0e17ef65f82ab018d8edd776e8dd940327b28b","https://ethplorer.io/address/0xbb0e17ef65f82ab018d8edd776e8dd940327b28b","https://bscscan.com/token/0x715D400F88C167884bbCc41C5FeA407ed4D2f8A0","https://bscscan.com/token/0x715d400f88c167884bbcc41c5fea407ed4d2f8a0","https://explorer.roninchain.com/token/ronin:97a9107c1793bc407d6f527b77e7fff4d812bece","https://explorer.energi.network/token/0x7cd3d51bee45434dd80822c5d58b999333b69ffb","","","",""],"official_forum_url":["","",""],"chat_url":["https://discord.com/invite/axie","",""],"announcement_url":["",""],"twitter_screen_name":"axieinfinity","facebook_username":"","bitcointalk_thread_identifier":null,"telegram_channel_identifier":"axieinfinity","subreddit_url":null,"repos_url":{"github":[],"bitbucket":[]}},"image":{"thumb":"https://assets.coingecko.com/coins/images/13029/thumb/axie_infinity_logo.png?1604471082","small":"https://assets.coingecko.com/coins/images/13029/small/axie_infinity_logo.png?1604471082","large":"https://assets.coingecko.com/coins/images/13029/large/axie_infinity_logo.png?1604471082"},"country_origin":"","genesis_date":null,"contract_address":"0xbb0e17ef65f82ab018d8edd776e8dd940327b28b","sentiment_votes_up_percentage":86.67,"sentiment_votes_down_percentage":13.33,"watchlist_portfolio_users":233728,"market_cap_rank":64,"coingecko_rank":412,"coingecko_score":29.892,"developer_score":0.0,"community_score":11.664,"liquidity_score":58.359,"public_interest_score":0.281,"market_data":{"current_price":{"aed":21.68,"ars":1539.53,"aud":8.84,"bch":0.02154543,"bdt":636.38,"bhd":2.22,"bmd":5.9,"bnb":0.02501985,"brl":28.74,"btc":0.00019492,"cad":7.85,"chf":5.25,"clp":4763.65,"cny":42.63,"czk":128.31,"dkk":40.1,"dot":1.146506,"eos":7.956943,"eth":0.00316055,"eur":5.38,"gbp":4.6,"hkd":46.22,"huf":2070.43,"idr":89510,"ils":21.83,"inr":487.94,"jpy":839.01,"krw":7666.92,"kwd":1.81,"lkr":1834.99,"ltc":0.06063751,"mmk":12398.98,"mxn":101.23,"myr":27.57,"ngn":4501.94,"nok":62.73,"nzd":9.51,"php":327.85,"pkr":1608.02,"pln":23.96,"rub":538.66,"sar":22.14,"sek":63.89,"sgd":7.97,"thb":206.53,"try":153.85,"twd":184.66,"uah":218.07,"usd":5.9,"vef":0.591139,"vnd":139617,"xag":0.255738,"xau":0.00306545,"xdr":4.43,"xlm":59.333,"xrp":12.560826,"yfi":0.00082556,"zar":112.59,"bits":194.92,"link":0.95080048,"sats":19491.81},"total_value_locked":null,"mcap_to_tvl_ratio":null,"fdv_to_tvl_ratio":null,"roi":null,"ath":{"aed":605.67,"ars":16474.1,"aud":222.99,"bch":0.28315295,"bdt":14143.92,"bhd":62.17,"bmd":164.9,"bnb":0.37070227,"brl":917.86,"btc":0.00326831,"cad":205.36,"chf":150.42,"clp":133798,"cny":1055.16,"czk":3607.85,"dkk":1060.26,"dot":5.030264,"eos":38.814844,"eth":0.04651435,"eur":142.75,"gbp":122.16,"hkd":1283.56,"huf":51176,"idr":2361310,"ils":512.8,"inr":12233.95,"jpy":18701.87,"krw":194827,"kwd":49.79,"lkr":33226,"ltc":0.9354862,"mmk":298131,"mxn":3354.22,"myr":685.97,"ngn":67694,"nok":1414.14,"nzd":231.83,"php":8301.44,"pkr":28057,"pln":655.51,"rub":11732.24,"sar":618.53,"sek":1449.29,"sgd":37.99,"thb":5484.12,"try":1960.24,"twd":4591.59,"uah":4304.1,"usd":164.9,"vef":209917,"vnd":3733700,"xag":6.97,"xau":0.091222,"xdr":117.08,"xlm":512.851,"xrp":153.205,"yfi":0.0053776,"zar":2480.64,"bits":3268.31,"link":6.20167,"sats":326831},"ath_change_percentage":{"aed":-96.42016,"ars":-90.65562,"aud":-96.03572,"bch":-92.38689,"bdt":-95.50105,"bhd":-96.42318,"bmd":-96.42007,"bnb":-93.24953,"brl":-96.86876,"btc":-94.03645,"cad":-96.17734,"chf":-96.5122,"clp":-96.43996,"cny":-95.96002,"czk":-96.44378,"dkk":-96.21852,"dot":-77.20364,"eos":-79.48729,"eth":-93.2047,"eur":-96.2303,"gbp":-96.23617,"hkd":-96.3996,"huf":-95.95462,"idr":-96.20961,"ils":-95.74326,"inr":-96.01191,"jpy":-95.51415,"krw":-96.06507,"kwd":-96.36156,"lkr":-94.47779,"ltc":-93.51657,"mmk":-95.84145,"mxn":-96.98221,"myr":-95.98118,"ngn":-93.35011,"nok":-95.56421,"nzd":-95.89852,"php":-96.05107,"pkr":-94.26928,"pln":-96.3456,"rub":-95.4091,"sar":-96.42006,"sek":-95.59234,"sgd":-79.02429,"thb":-96.23432,"try":-92.15203,"twd":-95.97867,"uah":-94.93397,"usd":-96.42007,"vef":-99.99972,"vnd":-96.26093,"xag":-96.33141,"xau":-96.63984,"xdr":-96.21861,"xlm":-88.43393,"xrp":-91.80162,"yfi":-84.64568,"zar":-95.4615,"bits":-94.03645,"link":-84.66194,"sats":-94.03645},"ath_date":{"aed":"2021-11-06T19:29:29.482Z","ars":"2021-11-06T19:29:29.482Z","aud":"2021-11-06T19:29:29.482Z","bch":"2021-10-04T11:05:28.225Z","bdt":"2021-11-06T19:29:29.482Z","bhd":"2021-11-06T19:29:29.482Z","bmd":"2021-11-06T19:29:29.482Z","bnb":"2021-10-04T11:01:13.565Z","brl":"2021-10-29T16:34:49.312Z","btc":"2021-10-04T11:05:28.225Z","cad":"2021-11-06T19:29:29.482Z","chf":"2021-11-06T19:29:29.482Z","clp":"2021-11-06T19:29:29.482Z","cny":"2021-11-06T19:29:29.482Z","czk":"2021-10-29T16:34:49.312Z","dkk":"2021-11-06T19:29:29.482Z","dot":"2021-10-04T11:05:28.225Z","eos":"2021-12-04T05:44:27.673Z","eth":"2021-10-04T11:01:13.565Z","eur":"2021-11-06T19:29:29.482Z","gbp":"2021-11-06T19:29:29.482Z","hkd":"2021-11-06T19:29:29.482Z","huf":"2021-11-06T19:29:29.482Z","idr":"2021-11-06T19:29:29.482Z","ils":"2021-11-06T19:29:29.482Z","inr":"2021-11-06T19:29:29.482Z","jpy":"2021-11-06T19:29:29.482Z","krw":"2021-11-06T19:29:29.482Z","kwd":"2021-11-06T19:29:29.482Z","lkr":"2021-11-06T19:29:29.482Z","ltc":"2021-10-04T11:05:28.225Z","mmk":"2021-11-06T19:29:29.482Z","mxn":"2021-11-06T19:29:29.482Z","myr":"2021-11-06T19:29:29.482Z","ngn":"2021-11-06T19:29:29.482Z","nok":"2021-11-06T19:29:29.482Z","nzd":"2021-11-06T19:29:29.482Z","php":"2021-11-06T19:29:29.482Z","pkr":"2021-11-06T19:29:29.482Z","pln":"2021-11-06T19:29:29.482Z","rub":"2021-11-06T19:29:29.482Z","sar":"2021-11-06T19:29:29.482Z","sek":"2021-11-06T19:29:29.482Z","sgd":"2022-05-31T04:59:05.148Z","thb":"2021-11-06T19:29:29.482Z","try":"2021-12-03T14:18:06.449Z","twd":"2021-11-06T19:29:29.482Z","uah":"2021-11-06T19:29:29.482Z","usd":"2021-11-06T19:29:29.482Z","vef":"2020-12-19T00:29:05.260Z","vnd":"2021-11-06T19:29:29.482Z","xag":"2021-10-04T11:05:28.225Z","xau":"2021-10-29T16:34:49.312Z","xdr":"2021-11-06T19:29:29.482Z","xlm":"2021-10-04T11:01:13.565Z","xrp":"2021-12-04T06:58:48.091Z","yfi":"2021-12-08T03:14:03.913Z","zar":"2021-11-06T19:29:29.482Z","bits":"2021-10-04T11:05:28.225Z","link":"2021-12-04T05:44:27.673Z","sats":"2021-10-04T11:05:28.225Z"},"atl":{"aed":0.454412,"ars":9.79,"aud":0.170017,"bch":0.00048816,"bdt":10.49,"bhd":0.04664977,"bmd":0.123718,"bnb":0.00429987,"brl":0.683617,"btc":7.88e-06,"cad":0.161577,"chf":0.111677,"clp":93.53,"cny":0.819484,"czk":2.78,"dkk":0.778289,"dot":0.02805716,"eos":0.04974706,"eth":0.00028493,"eur":0.104488,"gbp":0.094078,"hkd":0.959179,"huf":37.54,"idr":1762.93,"ils":0.418229,"inr":9.17,"jpy":12.8,"krw":138.66,"kwd":0.03779675,"lkr":22.82,"ltc":0.00201019,"mmk":159.46,"mxn":2.56,"myr":0.511884,"ngn":47.26,"nok":1.13,"nzd":0.182085,"php":5.96,"pkr":19.74,"pln":0.473368,"rub":9.55,"sar":0.463997,"sek":1.075,"sgd":0.166786,"thb":3.79,"try":1.046,"twd":3.53,"uah":3.49,"usd":0.123718,"vef":0.04182424,"vnd":2860.48,"xag":0.00489614,"xau":6.354e-05,"xdr":0.087344,"xlm":1.487501,"xrp":0.48732612,"yfi":9.06e-06,"zar":1.94,"bits":8.66,"link":0.01088485,"sats":865.77},"atl_change_percentage":{"aed":4671.42803,"ars":15631.85662,"aud":5099.37942,"bch":4315.9109,"bdt":5965.14198,"bhd":4666.64185,"bmd":4671.51377,"bnb":481.97388,"brl":4104.17374,"btc":2374.05437,"cad":4758.61705,"chf":4597.84279,"clp":4992.70394,"cny":5101.85623,"czk":4509.87216,"dkk":5051.49554,"dot":3987.07472,"eos":15904.91827,"eth":1009.33357,"eur":5050.09118,"gbp":4787.51674,"hkd":4717.98608,"huf":5414.24977,"idr":4976.95053,"ils":5119.23576,"inr":5219.44688,"jpy":6456.57254,"krw":5428.91123,"kwd":4693.11395,"lkr":7939.78842,"ltc":2917.20302,"mmk":7675.00599,"mxn":3853.92131,"myr":5285.61192,"ngn":9425.03524,"nok":5428.87392,"nzd":5121.90132,"php":5398.96675,"pkr":8045.65357,"pln":4960.53306,"rub":5542.66629,"sar":4672.20843,"sek":5842.07816,"sgd":4677.83514,"thb":5343.36675,"try":14614.03795,"twd":5128.13092,"uah":6140.94334,"usd":4671.51377,"vef":1313.27157,"vnd":4780.5009,"xag":5122.82494,"xau":4724.3809,"xdr":4968.56077,"xlm":3887.67521,"xrp":2477.39204,"yfi":9017.44355,"zar":5690.44865,"bits":2151.25732,"link":8638.89927,"sats":2151.25732},"atl_date":{"aed":"2020-11-06T08:05:43.662Z","ars":"2020-11-06T08:05:43.662Z","aud":"2020-11-06T08:05:43.662Z","bch":"2020-11-06T08:05:43.662Z","bdt":"2020-11-06T08:05:43.662Z","bhd":"2020-11-06T08:05:43.662Z","bmd":"2020-11-06T08:05:43.662Z","bnb":"2020-11-06T08:05:43.662Z","brl":"2020-11-06T08:05:43.662Z","btc":"2020-11-06T08:05:43.662Z","cad":"2020-11-06T08:05:43.662Z","chf":"2020-11-06T08:05:43.662Z","clp":"2020-11-06T08:05:43.662Z","cny":"2020-11-06T08:05:43.662Z","czk":"2020-11-06T08:05:43.662Z","dkk":"2020-11-06T08:05:43.662Z","dot":"2020-11-06T08:05:43.662Z","eos":"2020-11-06T08:05:43.662Z","eth":"2020-11-06T08:05:43.662Z","eur":"2020-11-06T08:05:43.662Z","gbp":"2020-11-06T08:05:43.662Z","hkd":"2020-11-06T08:05:43.662Z","huf":"2020-11-06T08:05:43.662Z","idr":"2020-11-06T08:05:43.662Z","ils":"2020-11-06T08:05:43.662Z","inr":"2020-11-06T08:05:43.662Z","jpy":"2020-11-06T08:05:43.662Z","krw":"2020-11-06T08:05:43.662Z","kwd":"2020-11-06T08:05:43.662Z","lkr":"2020-11-06T08:05:43.662Z","ltc":"2020-11-06T08:05:43.662Z","mmk":"2020-11-06T08:05:43.662Z","mxn":"2020-11-06T08:05:43.662Z","myr":"2020-11-06T08:05:43.662Z","ngn":"2020-11-06T08:05:43.662Z","nok":"2020-11-06T08:05:43.662Z","nzd":"2020-11-06T08:05:43.662Z","php":"2020-11-06T08:05:43.662Z","pkr":"2020-11-06T08:05:43.662Z","pln":"2020-11-06T08:05:43.662Z","rub":"2020-11-06T08:05:43.662Z","sar":"2020-11-06T08:05:43.662Z","sek":"2020-11-06T08:05:43.662Z","sgd":"2020-11-06T08:05:43.662Z","thb":"2020-11-06T08:05:43.662Z","try":"2020-11-06T08:05:43.662Z","twd":"2020-11-06T08:05:43.662Z","uah":"2020-11-06T08:05:43.662Z","usd":"2020-11-06T08:05:43.662Z","vef":"2021-01-11T16:47:59.846Z","vnd":"2020-11-06T08:05:43.662Z","xag":"2020-11-06T08:05:43.662Z","xau":"2020-11-06T08:05:43.662Z","xdr":"2020-11-06T08:05:43.662Z","xlm":"2020-11-06T08:05:43.662Z","xrp":"2020-11-06T08:05:43.662Z","yfi":"2020-11-07T01:21:54.346Z","zar":"2020-11-06T08:05:43.662Z","bits":"2020-11-06T00:00:00.000Z","link":"2020-11-06T08:05:43.662Z","sats":"2020-11-06T00:00:00.000Z"},"market_cap":{"aed":2507949634,"ars":178062575638,"aud":1022499717,"bch":2492890,"bdt":73603946908,"bhd":257206695,"bmd":682825461,"bnb":2893644,"brl":3324402672,"btc":22537,"cad":908055439,"chf":606849520,"clp":550965035951,"cny":4930819217,"czk":14840801692,"dkk":4637613964,"dot":132612469,"eos":920977208,"eth":365519,"eur":622447985,"gbp":531857531,"hkd":5345464977,"huf":239466889053,"idr":10352794786863,"ils":2524883706,"inr":56435456041,"jpy":97039740341,"krw":886758112738,"kwd":209552306,"lkr":212235197870,"ltc":7010923,"mmk":1434068386865,"mxn":11708476456,"myr":3188794901,"ngn":520695085568,"nok":7255771628,"nzd":1099823555,"php":37918661433,"pkr":185984293280,"pln":2770867481,"rub":62301593186,"sar":2561263964,"sek":7388956734,"sgd":921746089,"thb":23887539150,"try":17794567387,"twd":21357619606,"uah":25221473511,"usd":682825461,"vef":68371313,"vnd":16148177825001,"xag":29578749,"xau":354550,"xdr":512080174,"xlm":6857426545,"xrp":1452595417,"yfi":95475,"zar":13022553571,"bits":22537028245,"link":110013596,"sats":2253702824524},"market_cap_rank":64,"fully_diluted_valuation":{"aed":5854560325,"ars":415669468165,"aud":2386924440,"bch":5819405,"bdt":171821132861,"bhd":600423584,"bmd":1593988490,"bnb":6754925,"brl":7760489175,"btc":52610,"cad":2119765594,"chf":1416630173,"clp":1286173372765,"cny":11510509685,"czk":34644383439,"dkk":10826051027,"dot":309570691,"eos":2149930185,"eth":853269,"eur":1453043246,"gbp":1241568793,"hkd":12478459195,"huf":559011763473,"idr":24167575290125,"ils":5894091240,"inr":131742989307,"jpy":226529674268,"krw":2070049092534,"kwd":489179128,"lkr":495442074275,"ltc":16366306,"mmk":3347690785365,"mxn":27332280038,"myr":7443926249,"ngn":1215511168020,"nok":16937881094,"nzd":2567429291,"php":88517364049,"pkr":434161934354,"pln":6468316029,"rub":145436906169,"sar":5979017353,"sek":17248788549,"sgd":2151725063,"thb":55763097094,"try":41539657255,"twd":49857250189,"uah":58877034903,"usd":1593988490,"vef":159606068,"vnd":37696323690225,"xag":69048664,"xau":827663,"xdr":1195400510,"xlm":16007983904,"xrp":3390940306,"yfi":222877,"zar":30399863068,"bits":52610462986,"link":256815857,"sats":5261046298568},"total_volume":{"aed":108702814,"ars":7717819689,"aud":44318512,"bch":108009,"bdt":3190237974,"bhd":11148187,"bmd":29595909,"bnb":125427,"brl":144090583,"btc":977.143,"cad":39358120,"chf":26302861,"clp":23880643010,"cny":213717978,"czk":643249324,"dkk":201009495,"dot":5747545,"eos":39888912,"eth":15844,"eur":26978950,"gbp":23052461,"hkd":231690094,"huf":10379285285,"idr":448724293420,"ils":109436793,"inr":2446098919,"jpy":4206022607,"krw":38435023176,"kwd":9082689,"lkr":9198973916,"ltc":303982,"mmk":62157256747,"mxn":507484011,"myr":138212895,"ngn":22568643460,"nok":314489089,"nzd":47669983,"php":1643519930,"pkr":8061173075,"pln":120098541,"rub":2700356663,"sar":111013633,"sek":320261771,"sgd":39951518,"thb":1035364783,"try":771275278,"twd":925709720,"uah":1093181900,"usd":29595909,"vef":2963438,"vnd":699915320812,"xag":1282041,"xau":15367.38,"xdr":22195245,"xlm":297442077,"xrp":62968617,"yfi":4139,"zar":564440450,"bits":977142865,"link":4766453,"sats":97714286469},"high_24h":{"aed":21.84,"ars":1551.11,"aud":8.9,"bch":0.02226059,"bdt":640.92,"bhd":2.24,"bmd":5.95,"bnb":0.02523875,"brl":28.96,"btc":0.00019655,"cad":7.91,"chf":5.28,"clp":4797.62,"cny":42.94,"czk":129.23,"dkk":40.38,"dot":1.154901,"eos":8.25109,"eth":0.00319372,"eur":5.42,"gbp":4.63,"hkd":46.55,"huf":2085.2,"idr":90149,"ils":21.99,"inr":491.22,"jpy":844.99,"krw":7719.89,"kwd":1.82,"lkr":1848.07,"ltc":0.06108128,"mmk":12487.38,"mxn":101.95,"myr":27.77,"ngn":4534.04,"nok":63.18,"nzd":9.58,"php":330.18,"pkr":1619.49,"pln":24.14,"rub":542.5,"sar":22.3,"sek":64.34,"sgd":8.03,"thb":208.78,"try":154.95,"twd":185.97,"uah":219.62,"usd":5.95,"vef":0.595354,"vnd":140613,"xag":0.257562,"xau":0.0030873,"xdr":4.46,"xlm":61.14,"xrp":12.735859,"yfi":0.00084265,"zar":113.61,"bits":196.55,"link":0.9659884,"sats":19655.44},"low_24h":{"aed":20.96,"ars":1488.48,"aud":8.55,"bch":0.02104189,"bdt":615.28,"bhd":2.15,"bmd":5.71,"bnb":0.02432122,"brl":27.79,"btc":0.00018967,"cad":7.59,"chf":5.07,"clp":4605.7,"cny":41.22,"czk":124.06,"dkk":38.77,"dot":1.12682,"eos":7.893906,"eth":0.00309409,"eur":5.2,"gbp":4.45,"hkd":44.68,"huf":2001.78,"idr":86542,"ils":21.11,"inr":471.76,"jpy":811.19,"krw":7412.7,"kwd":1.75,"lkr":1774.14,"ltc":0.05876643,"mmk":11987.85,"mxn":97.87,"myr":26.66,"ngn":4352.66,"nok":60.65,"nzd":9.19,"php":316.97,"pkr":1554.7,"pln":23.16,"rub":520.8,"sar":21.41,"sek":61.77,"sgd":7.71,"thb":199.68,"try":148.75,"twd":178.54,"uah":210.83,"usd":5.71,"vef":0.571538,"vnd":134988,"xag":0.247258,"xau":0.0029638,"xdr":4.28,"xlm":58.077,"xrp":12.141573,"yfi":0.00081636,"zar":108.86,"bits":189.67,"link":0.93457851,"sats":18966.52},"price_change_24h":-0.04057407644817,"price_change_percentage_24h":-0.68257,"price_change_percentage_7d":-6.85357,"price_change_percentage_14d":-1.83361,"price_change_percentage_30d":-4.05451,"price_change_percentage_60d":-14.26159,"price_change_percentage_200d":-14.11722,"price_change_percentage_1y":-61.38836,"market_cap_change_24h":-5431895.618312,"market_cap_change_percentage_24h":-0.78922,"price_change_24h_in_currency":{"aed":-0.14902452538652966,"ars":-11.179697410021163,"aud":-0.0461229614340084,"bch":0.00035591,"bdt":-4.373609861983255,"bhd":-0.015283443116481887,"bmd":-0.04057407644816369,"bnb":-0.000176196849370112,"brl":-0.20561716288930398,"btc":-1.093930233653e-06,"cad":-0.0539574355645982,"chf":-0.034401062679344285,"clp":-32.73881654525485,"cny":-0.2929935208475527,"czk":-0.8616426078152131,"dkk":-0.279732018166996,"dot":-0.006544408573959881,"eos":-0.1992616164571448,"eth":-2.3539864515406e-05,"eur":-0.03574998175029709,"gbp":-0.03160343216400996,"hkd":-0.31020176136620137,"huf":-14.110442731917374,"idr":-615.171974884026,"ils":-0.15003076248241953,"inr":-3.148858597068454,"jpy":-5.587856056724945,"krw":-50.9901322685173,"kwd":-0.012451778321177056,"lkr":-12.611198087244475,"ltc":-0.000279582202162412,"mmk":-85.2135775729239,"mxn":-0.6957277462642821,"myr":-0.18948093701292024,"ngn":-30.940150046008057,"nok":-0.431144193745709,"nzd":-0.06072780139220768,"php":-2.253159491597671,"pkr":-11.051346747438856,"pln":-0.15919046825666783,"rub":-3.702014278021693,"sar":-0.14659892811949504,"sek":-0.4369776644838055,"sgd":-0.05477094579736352,"thb":-2.193014487160468,"try":-1.0573685064803726,"twd":-1.269088135368662,"uah":-1.4986816592835908,"usd":-0.04057407644816369,"vef":-0.004062682274754482,"vnd":-959.5386219757784,"xag":-0.001757594741173707,"xau":-2.106768345496e-05,"xdr":-0.030428244613775135,"xlm":-1.4827813554833895,"xrp":-0.1564417150384667,"yfi":-1.27775867872e-05,"zar":-1.0173193397417606,"bits":-1.0939302336527987,"link":-0.014709442944257243,"sats":-109.39302336528272},"price_change_percentage_1h_in_currency":{"aed":-0.11797,"ars":-0.11797,"aud":-0.11797,"bch":0.34504,"bdt":-0.11797,"bhd":-0.11797,"bmd":-0.11797,"bnb":0.12255,"brl":-0.11797,"btc":0.09601,"cad":-0.11797,"chf":-0.11797,"clp":-0.11797,"cny":-0.11797,"czk":-0.11797,"dkk":-0.11797,"dot":-0.0154,"eos":0.11684,"eth":0.01181,"eur":-0.11797,"gbp":-0.11797,"hkd":-0.11797,"huf":-0.11797,"idr":-0.11797,"ils":-0.11797,"inr":-0.11797,"jpy":-0.11797,"krw":-0.11797,"kwd":-0.11797,"lkr":-0.11797,"ltc":0.46633,"mmk":-0.11797,"mxn":-0.11797,"myr":-0.11797,"ngn":-0.11797,"nok":-0.11797,"nzd":-0.11797,"php":-0.11797,"pkr":-0.11797,"pln":-0.11797,"rub":-0.11797,"sar":-0.11797,"sek":-0.11797,"sgd":-0.11797,"thb":-0.11797,"try":-0.11797,"twd":-0.11797,"uah":-0.11797,"usd":-0.11797,"vef":-0.11797,"vnd":-0.11797,"xag":-0.11797,"xau":-0.11797,"xdr":-0.11797,"xlm":-0.17455,"xrp":0.15485,"yfi":0.22622,"zar":-0.11797,"bits":0.09601,"link":0.01613,"sats":0.09601},"price_change_percentage_24h_in_currency":{"aed":-0.68257,"ars":-0.72094,"aud":-0.51901,"bch":1.67967,"bdt":-0.68257,"bhd":-0.68257,"bmd":-0.68257,"bnb":-0.6993,"brl":-0.71029,"btc":-0.55809,"cad":-0.68257,"chf":-0.65138,"clp":-0.68257,"cny":-0.68257,"czk":-0.66703,"dkk":-0.69281,"dot":-0.56757,"eos":-2.44307,"eth":-0.7393,"eur":-0.6599,"gbp":-0.68257,"hkd":-0.66671,"huf":-0.67691,"idr":-0.68257,"ils":-0.68257,"inr":-0.6412,"jpy":-0.6616,"krw":-0.66067,"kwd":-0.68257,"lkr":-0.68257,"ltc":-0.45896,"mmk":-0.68257,"mxn":-0.68257,"myr":-0.68257,"ngn":-0.68257,"nok":-0.68257,"nzd":-0.63458,"php":-0.68257,"pkr":-0.68257,"pln":-0.6601,"rub":-0.68257,"sar":-0.65765,"sek":-0.67936,"sgd":-0.68257,"thb":-1.05067,"try":-0.68257,"twd":-0.68257,"uah":-0.68257,"usd":-0.68257,"vef":-0.68257,"vnd":-0.68257,"xag":-0.68257,"xau":-0.68257,"xdr":-0.68257,"xlm":-2.43815,"xrp":-1.23015,"yfi":-1.52416,"zar":-0.89544,"bits":-0.55809,"link":-1.52349,"sats":-0.55809},"price_change_percentage_7d_in_currency":{"aed":-6.85674,"ars":-5.3024,"aud":-7.06433,"bch":-4.01407,"bdt":-7.19179,"bhd":-6.83848,"bmd":-6.85357,"bnb":-3.31816,"brl":-5.32119,"btc":-5.9724,"cad":-6.50062,"chf":-7.47882,"clp":-6.22366,"cny":-7.27091,"czk":-7.0298,"dkk":-7.2992,"dot":-3.90824,"eos":-4.27413,"eth":-4.21951,"eur":-7.30839,"gbp":-7.81131,"hkd":-6.95103,"huf":-4.40019,"idr":-6.10172,"ils":-7.14636,"inr":-6.22539,"jpy":-8.28619,"krw":-8.10189,"kwd":-7.0323,"lkr":-6.01138,"ltc":3.56902,"mmk":-6.85044,"mxn":-6.72955,"myr":-6.80367,"ngn":-6.57305,"nok":-7.84655,"nzd":-7.91065,"php":-6.41879,"pkr":-11.446,"pln":-6.99411,"rub":-4.32124,"sar":-6.84929,"sek":-6.61841,"sgd":-7.012,"thb":-7.49243,"try":-6.82103,"twd":-6.50383,"uah":-6.8476,"usd":-6.85357,"vef":-6.85357,"vnd":-6.57087,"xag":-8.12057,"xau":-7.1611,"xdr":-6.86524,"xlm":-0.4132,"xrp":-4.70124,"yfi":-14.32398,"zar":-5.61024,"bits":-5.9724,"link":-3.17089,"sats":-5.9724},"price_change_percentage_14d_in_currency":{"aed":-1.83628,"ars":1.58583,"aud":-1.63365,"bch":-24.88476,"bdt":-2.18818,"bhd":-1.5183,"bmd":-1.83361,"bnb":-0.96154,"brl":-0.07909,"btc":-0.62364,"cad":-1.15664,"chf":-2.70026,"clp":-1.42557,"cny":-1.26894,"czk":-1.7192,"dkk":-2.46262,"dot":-3.15037,"eos":-3.49252,"eth":-0.89677,"eur":-2.31295,"gbp":-2.78565,"hkd":-1.85241,"huf":1.32429,"idr":-1.07413,"ils":0.02408,"inr":-1.00584,"jpy":-2.91299,"krw":-2.58411,"kwd":-1.63456,"lkr":-0.32451,"ltc":-9.55121,"mmk":-1.82722,"mxn":-1.92398,"myr":-1.97005,"ngn":-0.95513,"nok":-3.63288,"nzd":-2.86138,"php":-2.09278,"pkr":-6.67354,"pln":-2.21358,"rub":5.86923,"sar":-1.81513,"sek":-0.88608,"sgd":-1.97521,"thb":-2.17863,"try":1.20685,"twd":-0.96351,"uah":-1.8211,"usd":-1.83361,"vef":-1.83361,"vnd":-1.31125,"xag":-4.64872,"xau":-2.07689,"xdr":-1.28762,"xlm":-10.01249,"xrp":2.14719,"yfi":-12.13946,"zar":-0.12487,"bits":-0.62364,"link":-2.01252,"sats":-0.62364},"price_change_percentage_30d_in_currency":{"aed":-4.05709,"ars":2.37512,"aud":-3.69351,"bch":-61.07355,"bdt":-4.00054,"bhd":-4.14256,"bmd":-4.05451,"bnb":5.40295,"brl":-5.12439,"btc":-16.33776,"cad":-4.56082,"chf":-5.19465,"clp":-1.67983,"cny":-2.72221,"czk":-5.0432,"dkk":-5.73273,"dot":-6.92162,"eos":14.64569,"eth":-5.79038,"eur":-5.73917,"gbp":-6.21071,"hkd":-4.14102,"huf":-1.84693,"idr":-2.06964,"ils":-2.90519,"inr":-3.87144,"jpy":-2.07819,"krw":-3.8154,"kwd":-4.23767,"lkr":1.40403,"ltc":-13.81908,"mmk":-3.57844,"mxn":-5.37724,"myr":-2.85844,"ngn":59.23741,"nok":-6.58232,"nzd":-5.89839,"php":-4.89796,"pkr":-8.99142,"pln":-6.1829,"rub":6.7131,"sar":-4.03875,"sek":-3.95133,"sgd":-3.58769,"thb":-3.11714,"try":6.23868,"twd":-2.32829,"uah":-3.56124,"usd":-4.05451,"vef":-4.05451,"vnd":-3.39647,"xag":1.00147,"xau":-2.16273,"xdr":-3.81531,"xlm":-16.25931,"xrp":7.3356,"yfi":-20.93416,"zar":-3.15673,"bits":-16.33776,"link":-8.1283,"sats":-16.33776},"price_change_percentage_60d_in_currency":{"aed":-14.24092,"ars":-1.96697,"aud":-13.1497,"bch":-62.21782,"bdt":-14.69855,"bhd":-14.33527,"bmd":-14.26159,"bnb":13.89929,"brl":-16.30727,"btc":-21.59876,"cad":-14.79498,"chf":-14.3722,"clp":-12.50494,"cny":-10.62273,"czk":-12.58032,"dkk":-14.16366,"dot":-11.07716,"eos":6.42614,"eth":-15.18881,"eur":-14.22047,"gbp":-15.6695,"hkd":-14.35786,"huf":-11.12597,"idr":-11.8321,"ils":-13.48835,"inr":-13.69258,"jpy":-9.86971,"krw":-15.88727,"kwd":-14.16817,"lkr":-16.2618,"ltc":-29.38093,"mmk":-14.33201,"mxn":-17.22351,"myr":-10.00261,"ngn":41.85175,"nok":-13.76738,"nzd":-12.39911,"php":-14.7284,"pkr":-18.20688,"pln":-16.14315,"rub":0.68005,"sar":-14.2495,"sek":-8.86384,"sgd":-12.78956,"thb":-10.85283,"try":14.44582,"twd":-12.70482,"uah":-14.31698,"usd":-14.26159,"vef":-14.26159,"vnd":-13.61272,"xag":-4.97651,"xau":-9.55321,"xdr":-13.15451,"xlm":-23.09753,"xrp":-21.02623,"yfi":-12.98047,"zar":-12.23285,"bits":-21.59876,"link":-9.93062,"sats":-21.59876},"price_change_percentage_200d_in_currency":{"aed":-14.10576,"ars":28.77261,"aud":-14.03427,"bch":-68.05721,"bdt":-9.98753,"bhd":-14.18101,"bmd":-14.11722,"bnb":-9.09239,"brl":-19.59372,"btc":-52.18871,"cad":-16.04647,"chf":-17.73385,"clp":-21.81296,"cny":-11.00411,"czk":-18.08602,"dkk":-16.77743,"dot":-24.01777,"eos":2.52719,"eth":-44.30067,"eur":-16.90484,"gbp":-18.64572,"hkd":-13.72322,"huf":-20.48445,"idr":-16.48577,"ils":-8.3239,"inr":-14.18429,"jpy":-7.55002,"krw":-13.34519,"kwd":-13.89866,"lkr":-27.11261,"ltc":-41.52099,"mmk":-14.28261,"mxn":-25.5338,"myr":-9.61745,"ngn":46.71064,"nok":-7.70442,"nzd":-12.49943,"php":-13.6945,"pkr":3.24044,"pln":-20.82263,"rub":11.54478,"sar":-14.34284,"sek":-10.94612,"sgd":-14.29569,"thb":-13.5056,"try":19.96297,"twd":-12.53989,"uah":-13.85607,"usd":-14.11722,"vef":-14.11722,"vnd":-14.34066,"xag":-10.38578,"xau":-18.99699,"xdr":-14.55553,"xlm":-34.67017,"xrp":-37.0253,"yfi":-32.74489,"zar":-5.38528,"bits":-52.18871,"link":-17.74243,"sats":-52.18871},"price_change_percentage_1y_in_currency":{"aed":-61.38988,"ars":-20.56263,"aud":-60.35982,"bch":-84.62965,"bdt":-55.48795,"bhd":-61.41929,"bmd":-61.38836,"bnb":-60.41997,"brl":-64.23089,"btc":-72.51147,"cad":-60.30832,"chf":-64.86982,"clp":-68.0166,"cny":-58.35488,"czk":-65.31024,"dkk":-64.10464,"dot":-46.79891,"eos":-46.7218,"eth":-74.91519,"eur":-64.14522,"gbp":-63.82143,"hkd":-61.48739,"huf":-65.94975,"idr":-60.91206,"ils":-58.72628,"inr":-59.7733,"jpy":-59.68041,"krw":-61.27295,"kwd":-61.46345,"lkr":-66.95077,"ltc":-79.47457,"mmk":-56.21619,"mxn":-67.64892,"myr":-59.25974,"ngn":-29.59277,"nok":-59.24504,"nzd":-61.46,"php":-61.68402,"pkr":-49.09018,"pln":-66.57517,"rub":-45.80053,"sar":-61.42098,"sek":-60.19236,"sgd":-62.74882,"thb":-62.32357,"try":-41.74668,"twd":-59.42323,"uah":-51.70047,"usd":-61.38836,"vef":-61.38836,"vnd":-60.90439,"xag":-67.69319,"xau":-65.06828,"xdr":-60.60952,"xlm":-56.36499,"xrp":-71.95028,"yfi":-65.49417,"zar":-56.14134,"bits":-72.51147,"link":-60.23266,"sats":-72.51147},"market_cap_change_24h_in_currency":{"aed":-19950809.41650772,"ars":-1485855340.7957458,"aud":-8134013.821225762,"bch":42791,"bdt":-585521454.219101,"bhd":-2046086.4415070415,"bmd":-5431895.618311524,"bnb":-21723.660746885464,"brl":-29131296.347726822,"btc":-149.26858787951278,"cad":-7223606.388015389,"chf":-4827504.88855052,"clp":-4382942255.459717,"cny":-39224804.6389637,"czk":-118058992.12669373,"dkk":-36892348.660461426,"dot":-770103.4947003424,"eos":-22047429.762184978,"eth":-3023.455088766059,"eur":-4808433.581950307,"gbp":-4189646.078998029,"hkd":-42523323.25317764,"huf":-1904965793.3435974,"idr":-82356771796.1875,"ils":-20085520.427824974,"inr":-425257876.2331772,"jpy":-771953845.7965546,"krw":-6857143676.892944,"kwd":-1666994.4463043213,"lkr":-1688336929.105896,"ltc":-31034.97877458483,"mmk":-11408054086.712402,"mxn":-93141257.35677147,"myr":-25366952.53752899,"ngn":-4142143954.3934326,"nok":-89414117.2862978,"nzd":-8392609.802388191,"php":-301644011.18048096,"pkr":-1479510249.618744,"pln":-23666615.593762875,"rub":-495610914.555542,"sar":-20374926.394480705,"sek":-58779357.27010536,"sgd":-7332515.895161033,"thb":-280937267.30952835,"try":-141556280.76047897,"twd":-169900460.71829987,"uah":-200637526.49329758,"usd":-5431895.618311524,"vef":-543895.7082619071,"vnd":-128459205792.95312,"xag":-235299.77781653404,"xau":-2820.4574808534235,"xdr":-4073612.0956835747,"xlm":-179325373.21722317,"xrp":-19464804.989955425,"yfi":-1165.5783250366076,"zar":-131789240.11723328,"bits":-149268587.87949753,"link":-1592165.7378786206,"sats":-14926858787.951172},"market_cap_change_percentage_24h_in_currency":{"aed":-0.78922,"ars":-0.82755,"aud":-0.78922,"bch":1.7465,"bdt":-0.78922,"bhd":-0.78922,"bmd":-0.78922,"bnb":-0.74514,"brl":-0.86867,"btc":-0.65797,"cad":-0.78922,"chf":-0.78922,"clp":-0.78922,"cny":-0.78922,"czk":-0.78922,"dkk":-0.78922,"dot":-0.57736,"eos":-2.33795,"eth":-0.82038,"eur":-0.76658,"gbp":-0.78158,"hkd":-0.78922,"huf":-0.78922,"idr":-0.78922,"ils":-0.78922,"inr":-0.74789,"jpy":-0.78922,"krw":-0.76735,"kwd":-0.78922,"lkr":-0.78922,"ltc":-0.44072,"mmk":-0.78922,"mxn":-0.78922,"myr":-0.78922,"ngn":-0.78922,"nok":-1.21732,"nzd":-0.75731,"php":-0.78922,"pkr":-0.78922,"pln":-0.84689,"rub":-0.78922,"sar":-0.78922,"sek":-0.78922,"sgd":-0.78922,"thb":-1.16241,"try":-0.78922,"twd":-0.78922,"uah":-0.78922,"usd":-0.78922,"vef":-0.78922,"vnd":-0.78922,"xag":-0.78922,"xau":-0.78922,"xdr":-0.78922,"xlm":-2.54841,"xrp":-1.32228,"yfi":-1.2061,"zar":-1.00187,"bits":-0.65797,"link":-1.4266,"sats":-0.65797},"total_supply":270000000.0,"max_supply":270000000.0,"circulating_supply":115661358.61362292,"last_updated":"2023-07-09T03:25:57.004Z"},"public_interest_stats":{"alexa_rank":33612,"bing_matches":null},"status_updates":[],"last_updated":"2023-07-09T03:25:57.004Z"}
```

色々出力されるんですが、`MarketData.CurrentPrice`が欲しいので抜き出します。
各言語によって違うかと思いますが、Goでは、構造体に格納するのが楽なので構造体を作ります。

### 現在の市場価値を取得する

```go:main.go : 構造体追加
type CoinData struct {
	MarketData struct {
		CurrentPrice struct {
			Jpy float64 `json:"jpy"`
			Usd float64 `json:"usd"`
		} `json:"current_price"`
	} `json:"market_data"`
}
```

```go:main.go : fmt.Println(string(body))書き換え
	var coinData CoinData
	err = json.Unmarshal(body, &coinData)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("USD : %f\n", coinData.MarketData.CurrentPrice.Usd)
	fmt.Printf("JPY : %f\n", coinData.MarketData.CurrentPrice.Jpy)
```

構造体を作って`json.Unmarshal`で格納します。

(JSONから構造体を作る際に便利なサイトがあり、別の記事で紹介しているのでぜひ使ってみてください。)
[後で載せます]()

```go:出力結果
USD : 5.910000
JPY : 840.520000
```

こちらが、1リップルあたりの米国ドルと日本円価格になります。

こんな感じで、誰でも簡単に現在の市場価値を取得することができました!!
コードを載せておきます。

https://github.com/MoriKeigoYUZU/coingecko-rec

# 最後に
CoinGeckoでは、誰でも簡単に仮想通貨情報を取得することができます。
少しでもブロックチェーンに興味ある人は遊んでみてください!
[@morikeigo_](https://twitter.com/morikeigo_)