[암호화폐] 특정 암호화폐의 현재가를 알고 싶다면 coingecko로 가~요~ by tradingideas

View this thread on steempeak.com
· @tradingideas ·
$142.36
[암호화폐] 특정 암호화폐의 현재가를 알고 싶다면 coingecko로 가~요~
본인이 보유하고 있는 암호화폐의 현재가를 한번에 알 수 있으면 편할 것 같습니다.
그리고 yieldwatch의 경우에는 LP로 공급중인 pair들의 현재 가치를 보여주는 기능이 있습니다. 이를 구현하기 위해서는 코인들의 현재가를 알아야 합니다.

코인은 상장된 곳이 다양하기 때문에 특정 거래소에서 모든 값을 구할 수가 없습니다. 그렇다고 여기 저기 API를 이용해서 현재가를 받아오는 것도 조금 귀찮기는하죠.

그러던 중 coingecko에서 지원하는 API에서 거의 모든 코인의 현재가와 관련 정보를 제공한다는 사실을 발견하였습니다.

https://www.coingecko.com/en/api

![](https://cdn.steemitimages.com/DQmNpAXYF5UUX8SxiEb22vrkxDAsfjJYoXd2UQhk51jXrFZ/image.png)

API문서는 아래 사이트에서 확인이 가능합니다.
https://www.coingecko.com/api/documentations/v3

API 문서보고 하나하나 개발하면 되겠지만,, 누군가 API를 만들어 놓았겠죠. 찾아보겠습니다.

역시나.. 고마우신 분이 계시군요.

https://github.com/man-c/pycoingecko

> CoinGecko API wrapper

그럼 coingecko API를 이용하여 원하는 코인의 현재가를 확인하는 방법에 대하여 기술하도록 하겠습니다.

우선 pycoingecko를 설치합니다.

~~~
pip install pycoingecko 
~~~

coingecko API를 이용하여 특정 코인을 검색하기 위해서는 coingecko에서 사용하는 코인의 id를 알아야합니다. coingecko API에서 BTC와 같은 coin의 ticker를 사용하지 않고 bitcoin과 같이 별도의 coin id를 사용하는 이유는 코인 ticker가 중복되는 경우가 많기 때문입니다. 실제로 uni의 경우에도 동일한 ticker를 사용하는 코인이 두 개가 나옵니다. 이런 경우에는 별도의 확인 과정이 필요합니다.

uni의 경우에는 id로 uniswap를 사용합니다. 이런 사실을 확인한 후 uni에 대한 코인의 id를 별도로 처리하여야 합니다.

~~~
            if each['symbol'] == 'uni'  :
                if each['id'] == 'uniswap' :
~~~

이하 전체 소스입니다. 현재가를 알고 싶은 ticker  list를 제공하면 해당하는 코인의 현재가를 돌려주는 내용입니다.

~~~

from pycoingecko import CoinGeckoAPI


def get_name_using_ticker(tokens) :
    name_tickers = {}
    coins = quoter.get_coins_list()
    for each in coins :
        if each['symbol'].upper() in tokens : # 찾는 coin이 있다.
            if each['symbol'] == 'uni'  :
                if each['id'] == 'uniswap' :
                    name_tickers[each['symbol'].upper()] = each
            else :
                name_tickers[each['symbol'].upper()] = each

    return name_tickers


quoter = CoinGeckoAPI()


int_tokens = ['BTC', 'ETH', 'BNB', 'CAKE', 'FLOW', 'UNI', 'HT', 'LUNA', 'MIR', 'CRO', 'STEEM', 'SBD', 'TRX']

gecko_name = get_name_using_ticker(int_tokens)

for ticker in int_tokens:
    id = gecko_name[ticker]['id']
    coin_price = quoter.get_price(ids=id, vs_currencies='usd')
    print('%6s : %12.3f'%(gecko_name[ticker]['symbol'], float(coin_price[id]['usd'])))


print('')

~~~

출력결과입니다.

![](https://cdn.steemitimages.com/DQmQuYbFKUQATDdSBJuFBNBVmUwgenFA4hLrLArS1cLGGgT/image.png)

현재 값이 정확하게 출력이 되는군요.

지난 번에 설명한 유동성 공급중인 smart contract 주소를 기반으로 해당하는 코인의 종류와 수량을 확인하고, 이번에 소개해드린 코인의 현재가를 기반으로 yieldwatch와 같이 현재가 기준의 자산 가치를 출력해줄 수 있을 것 같습니다. 이것도 마무리한 후 소스를 공개하도록 하겠습니다.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 93 others
👎  
properties (23)
post_id89,720,313
authortradingideas
permlinkcoingecko
categoryhive-101145
json_metadata{"tags":["hive-101145","sct-kr","sct-freeboard","s","union","mini","jjm","lgt","sct"],"image":["https:\/\/cdn.steemitimages.com\/DQmNpAXYF5UUX8SxiEb22vrkxDAsfjJYoXd2UQhk51jXrFZ\/image.png","https:\/\/cdn.steemitimages.com\/DQmQuYbFKUQATDdSBJuFBNBVmUwgenFA4hLrLArS1cLGGgT\/image.png"],"links":["https:\/\/www.coingecko.com\/en\/api","https:\/\/www.coingecko.com\/api\/documentations\/v3","https:\/\/github.com\/man-c\/pycoingecko"],"app":"steemcoinpan\/0.1","format":"markdown","canonical_url":"https:\/\/www.steemcoinpan.com\/@tradingideas\/coingecko"}
created2021-03-06 11:35:12
last_update2021-03-06 11:35:12
depth0
children11
net_rshares151,725,696,647,552
last_payout2021-03-13 11:35:12
cashout_time1969-12-31 23:59:59
total_payout_value75.658 SBD
curator_payout_value66.701 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length2,443
author_reputation3,154,197,541,442,728
root_title"[암호화폐] 특정 암호화폐의 현재가를 알고 싶다면 coingecko로 가~요~"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (158)
@upvu ·
<a href="https://coupa.ng/bHgxg2" target="_blank"><img src="https://ads-partners.coupang.com/banners/273554?subId=&traceId=V0-301-879dd1202e5c73b2-I273554&w=728&h=90" alt=""></a>
<div class='shr_item' style='position:relative; min-height:158px; margin:12px 0; padding:9px 10px; border:1px solid #dbdbdb; border-radius:1px; background-color:#fff;'><div class='item_dtl' style='position:relative; height:158px; padding:5px; border:1px solid #f0f1f4;'><span class='thmb' style='float:left; overflow:hidden; width:156px; height:156px; margin-right:9px; border:1px solid #e7e7e7;'><a href='https://qoo.tn/AoaPVR/Q163214049'><img src='https://steemitimages.com/240x0/https://gd.image-gmkt.com/li/061/293/1455293061.g_400-w-st_g.jpg' width='156' alt='' style='vertical-align: middle; border: 0 none;'></a></span><p class='tit' style='overflow:hidden; max-height:68px; margin-bottom:7px; line-height:17px; color:#000;'>[US$49.00](▼14%)[Nespresso]스타벅스 네스프레소 호환 캡슐 7종 / 120 캡슐 골라담기 / 20개씩 총 6종류 교차 선택 가능 / 중복 선택 가능 / 재고 확보 / 무료배송 / 개당 약 486원 최저가★</p><span class='url' style='position:absolute; left:170px; bottom:10px; display:block; font-weight:bold; color:#9197a3;'>WWW.QOO10.COM</span></div></div>
properties (22)
post_id89,720,323
authorupvu
permlinkre--coingecko-20210306t113610327z
categoryhive-101145
json_metadata{"tags":["hive-101145","sct-kr","sct-freeboard","s","union","mini","jjm","lgt","sct"]}
created2021-03-06 11:36:12
last_update2021-03-06 11:36:12
depth1
children1
net_rshares0
last_payout2021-03-13 11:36:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length1,191
author_reputation27,754,495,235,856
root_title"[암호화폐] 특정 암호화폐의 현재가를 알고 싶다면 coingecko로 가~요~"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@perpetuator ·
re-upvu-re--coingecko-20210306t113610327z-20210315t022027204z
![](https://steemitimages.com/p/4i88GgaV8qiFU89taP2MgKXzwntUGAvkoQiKU7VxyD37q9FfkXRmza8i4BGz9rhzfHcytcvqSnc6m8nTz76ZuNbkKqZuiCfeHmQe142nDa3TVZ4g6ycYDUiXs3?format=match&mode=fit)
👍  
properties (23)
post_id89,844,215
authorperpetuator
permlinkre-upvu-re--coingecko-20210306t113610327z-20210315t022027204z
categoryhive-101145
json_metadata{}
created2021-03-15 02:20:30
last_update2021-03-15 02:20:30
depth2
children0
net_rshares6,235,778,110
last_payout2021-03-22 02:20:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length177
author_reputation24,297,162,348,293
root_title"[암호화폐] 특정 암호화폐의 현재가를 알고 싶다면 coingecko로 가~요~"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@zzings ·
정말 대단하십니다!
properties (22)
post_id89,720,354
authorzzings
permlinkre-tradingideas-qpjpq2
categoryhive-101145
json_metadata{"tags":["hive-101145"],"app":"steempeak\/2020.07.1"}
created2021-03-06 11:39:42
last_update2021-03-06 11:39:42
depth1
children0
net_rshares0
last_payout2021-03-13 11:39:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length10
author_reputation1,646,897,865,482,869
root_title"[암호화폐] 특정 암호화폐의 현재가를 알고 싶다면 coingecko로 가~요~"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@sct.krwp ·
@tradingideas transfered 15 KRWP to @krwp.burn. voting percent : 53.76%, voting power : 81.05%, steem power : 1722169.90, STU KRW : 1200. 
@tradingideas staking status : 7500 KRWP
                                @tradingideas limit for KRWP voting service : 22.5 KRWP (rate : 0.003)
                                What you sent : 15 KRWP [51772618 - cd89f2752bcf24bdbdf0885ec7d8fd70ad444a08]
properties (22)
post_id89,720,409
authorsct.krwp
permlinkre--coingecko-20210306t114632855z
categoryhive-101145
json_metadata{"tags":["hive-101145","sct-kr","sct-freeboard","s","union","mini","jjm","lgt","sct"]}
created2021-03-06 11:46:36
last_update2021-03-06 11:46:36
depth1
children0
net_rshares0
last_payout2021-03-13 11:46:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length392
author_reputation10,000,000,000,000
root_title"[암호화폐] 특정 암호화폐의 현재가를 알고 싶다면 coingecko로 가~요~"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@steem3344 ·
좋은 정보 감사합니다.
properties (22)
post_id89,720,482
authorsteem3344
permlinkqpjqe5
categoryhive-101145
json_metadata{"app":"steemit\/0.2"}
created2021-03-06 11:54:06
last_update2021-03-06 11:54:06
depth1
children0
net_rshares0
last_payout2021-03-13 11:54:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length12
author_reputation1,449,142,558,794
root_title"[암호화폐] 특정 암호화폐의 현재가를 알고 싶다면 coingecko로 가~요~"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@tailcock ·
한 번에 모든 거래소 가격을 다 알 수 있겠군요.
properties (22)
post_id89,721,312
authortailcock
permlinkqpjtrg
categoryhive-101145
json_metadata{"tags":["sct"],"app":"steemcoinpan\/0.1","canonical_url":"https:\/\/www.steemcoinpan.com\/@tailcock\/qpjtrg"}
created2021-03-06 13:06:51
last_update2021-03-06 13:06:51
depth1
children1
net_rshares0
last_payout2021-03-13 13:06:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length27
author_reputation238,658,978,685,858
root_title"[암호화폐] 특정 암호화폐의 현재가를 알고 싶다면 coingecko로 가~요~"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@tradingideas ·
사용법도 간단하고 아주 굿입니다.
properties (22)
post_id89,721,681
authortradingideas
permlinkqpjv8f
categoryhive-101145
json_metadata{"tags":["sct"],"app":"steemcoinpan\/0.1","canonical_url":"https:\/\/www.steemcoinpan.com\/@tradingideas\/qpjv8f"}
created2021-03-06 13:38:39
last_update2021-03-06 13:38:39
depth2
children0
net_rshares0
last_payout2021-03-13 13:38:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length18
author_reputation3,154,197,541,442,728
root_title"[암호화폐] 특정 암호화폐의 현재가를 알고 싶다면 coingecko로 가~요~"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@gfriend96 ·
오.. 역시 트아형님
멋지십니다.
properties (22)
post_id89,723,367
authorgfriend96
permlinkqpk1jm
categoryhive-101145
json_metadata{"tags":["sct"],"app":"steemcoinpan\/0.1","canonical_url":"https:\/\/www.steemcoinpan.com\/@gfriend96\/qpk1jm"}
created2021-03-06 15:55:00
last_update2021-03-06 15:55:00
depth1
children0
net_rshares0
last_payout2021-03-13 15:55:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length18
author_reputation189,573,565,240,637
root_title"[암호화폐] 특정 암호화폐의 현재가를 알고 싶다면 coingecko로 가~요~"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@rumi3250 ·
좋은 정보 알려 주셔서 감사드립니다. 좋은 주말 되세요. ^^
properties (22)
post_id89,723,726
authorrumi3250
permlinkqpk31v
categoryhive-101145
json_metadata{"app":"steemit\/0.2"}
created2021-03-06 16:27:36
last_update2021-03-06 16:27:36
depth1
children0
net_rshares0
last_payout2021-03-13 16:27:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length34
author_reputation882,176,644,185
root_title"[암호화폐] 특정 암호화폐의 현재가를 알고 싶다면 coingecko로 가~요~"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@rafacelis ·
Very good 👍🏻
properties (22)
post_id89,730,101
authorrafacelis
permlinkqpl1dc
categoryhive-101145
json_metadata{"app":"steemit\/0.2"}
created2021-03-07 04:48:57
last_update2021-03-07 04:48:57
depth1
children0
net_rshares0
last_payout2021-03-14 04:48:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length12
author_reputation726,291,750,173
root_title"[암호화폐] 특정 암호화폐의 현재가를 알고 싶다면 coingecko로 가~요~"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@yh70 ·
어렵군요...
코린이라^^
properties (22)
post_id89,732,057
authoryh70
permlinkqplem8
categoryhive-101145
json_metadata{"app":"steemit\/0.2"}
created2021-03-07 09:34:57
last_update2021-03-07 09:34:57
depth1
children0
net_rshares0
last_payout2021-03-14 09:34:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length14
author_reputation199,526,231,496,888
root_title"[암호화폐] 특정 암호화폐의 현재가를 알고 싶다면 coingecko로 가~요~"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000