From ee9ed687280215034d5539e731a80675324372ae Mon Sep 17 00:00:00 2001 From: Ryon Date: Mon, 20 Mar 2023 00:51:15 -0400 Subject: [PATCH 1/2] coingecko --- integrations/coingecko.py | 217 +++++++++++++++++++++++++++++++++++++ knowledge_base/widgets.txt | 44 ++++++++ tools/index_widget.py | 27 +++++ 3 files changed, 288 insertions(+) create mode 100644 integrations/coingecko.py diff --git a/integrations/coingecko.py b/integrations/coingecko.py new file mode 100644 index 00000000..5564d771 --- /dev/null +++ b/integrations/coingecko.py @@ -0,0 +1,217 @@ +import requests + +""" +List all supported NFT, ordered by 24h trading volume of native token +Response in the format: +[{'id': 'drawshop-kingdom-reverse', + 'contract_address': '0x253ebdb767f18002a22cbb26176356efeb0bf641', + 'name': 'Drawshop Kingdom Reverse', + 'asset_platform_id': 'klay-token', + 'symbol': 'DKR'}, + {'id': 'puuvillasociety', + 'contract_address': '0xd643bb39f81ff9079436f726d2ed27abc547cb38', + 'name': 'Puuvilla Society', + 'asset_platform_id': 'klay-token', + 'symbol': 'Puuvilla'}] +""" +def get_top_nft_by_24h_native_token(): + url = f'https://api.coingecko.com/api/v3/nfts/list?order=h24_volume_native_desc' + response = requests.get(url) + response.raise_for_status() + result = response.json() + return result + +""" +List all supported NFT, ordered by floor price of native token +Response in the format: +[{'id': 'drawshop-kingdom-reverse', + 'contract_address': '0x253ebdb767f18002a22cbb26176356efeb0bf641', + 'name': 'Drawshop Kingdom Reverse', + 'asset_platform_id': 'klay-token', + 'symbol': 'DKR'}, + {'id': 'puuvillasociety', + 'contract_address': '0xd643bb39f81ff9079436f726d2ed27abc547cb38', + 'name': 'Puuvilla Society', + 'asset_platform_id': 'klay-token', + 'symbol': 'Puuvilla'}] +""" +def get_top_nft_by_floor_price_native_token(): + url = f'https://api.coingecko.com/api/v3/nfts/list?order=floor_price_native_desc' + response = requests.get(url) + response.raise_for_status() + result = response.json() + return result + +""" +List all supported NFT, ordered by market cap of native token +Response in the format: +[{'id': 'drawshop-kingdom-reverse', + 'contract_address': '0x253ebdb767f18002a22cbb26176356efeb0bf641', + 'name': 'Drawshop Kingdom Reverse', + 'asset_platform_id': 'klay-token', + 'symbol': 'DKR'}, + {'id': 'puuvillasociety', + 'contract_address': '0xd643bb39f81ff9079436f726d2ed27abc547cb38', + 'name': 'Puuvilla Society', + 'asset_platform_id': 'klay-token', + 'symbol': 'Puuvilla'}] +""" +def get_top_nft_by_market_cap_native_token(): + url = f'https://api.coingecko.com/api/v3/nfts/list?order=market_cap_native_desc' + response = requests.get(url) + response.raise_for_status() + result = response.json() + return result + +""" +List all supported NFT, ordered by market cap of USD +Response in the format: +[{'id': 'drawshop-kingdom-reverse', + 'contract_address': '0x253ebdb767f18002a22cbb26176356efeb0bf641', + 'name': 'Drawshop Kingdom Reverse', + 'asset_platform_id': 'klay-token', + 'symbol': 'DKR'}, + {'id': 'puuvillasociety', + 'contract_address': '0xd643bb39f81ff9079436f726d2ed27abc547cb38', + 'name': 'Puuvilla Society', + 'asset_platform_id': 'klay-token', + 'symbol': 'Puuvilla'}] +""" +def get_top_nft_by_marketcap_usd(): + url = f'https://api.coingecko.com/api/v3/nfts/list?order=market_cap_usd_desc' + response = requests.get(url) + response.raise_for_status() + result = response.json() + return result + + +""" +Top-7 trending coins on CoinGecko as searched by users in the last 24 hours (Ordered by most popular first) +Response in the format: +{ + "coins": [ + { + "item": { + "id": "camelot-token", + "coin_id": 28416, + "name": "Camelot Token", + "symbol": "GRAIL", + "market_cap_rank": 500, + "thumb": "https://assets.coingecko.com/coins/images/28416/thumb/vj5DIMhP_400x400.jpeg?1670457013", + "small": "https://assets.coingecko.com/coins/images/28416/small/vj5DIMhP_400x400.jpeg?1670457013", + "large": "https://assets.coingecko.com/coins/images/28416/large/vj5DIMhP_400x400.jpeg?1670457013", + "slug": "camelot-token", + "price_btc": 0.16421050648435834, + "score": 0 + } + }] +""" +def get_top_searched_token_last_24h(): + url = f'https://api.coingecko.com/api/v3/search/trending' + response = requests.get(url) + response.raise_for_status() + result = response.json() + return result + +""" +Get Top 100 Cryptocurrency Global Decentralized Finance(defi) data +Response in the format: +{ + "data": { + "defi_market_cap": "49345991438.7624632293259565585", + "eth_market_cap": "215715925887.586366238685068393", + "defi_to_eth_ratio": "22.8754512378829132927013639333919477262638870348465613291519787", + "trading_volume_24h": "3451809782.9077426466020906851", + "defi_dominance": "4.0986673335718624991995052507291142723503369772850766789102689", + "top_coin_name": "Lido Staked Ether", + "top_coin_defi_dominance": 21.084575288583714 + } +} +""" +def getGlobalDefiData(): + url = f'https://api.coingecko.com/api/v3/global/decentralized_finance_defi' + response = requests.get(url) + response.raise_for_status() + result = response.json()['data'] + return result + +""" +Get Defi Market Cap +""" +def get_defi_market_cap(): + data=getGlobalDefiData() + return data['defi_market_cap'] + +""" +Get Ether Market Cap +""" +def get_eth_market_cap(): + data=getGlobalDefiData() + return data['eth_market_cap'] + +""" +Get Trading Volumn in the last 24h +""" +def get_trading_volume_last_24h(): + data=getGlobalDefiData() + return data['trading_volume_24h'] + +""" +Get Top Coin Volume +""" +def get_top_coin_name(): + data=getGlobalDefiData() + return data['top_coin_name'] + + +""" +Get public companies bitcoin or ethereum holdings (Ordered by total holdings descending) +Response in the format: +{ + "total_holdings": 174374.4658, + "total_value_usd": 4764147923.454023, + "market_cap_dominance": 0.9, + "companies": [ + { + "name": "MicroStrategy Inc.", + "symbol": "NASDAQ:MSTR", + "country": "US", + "total_holdings": 129699, + "total_entry_value_usd": 3975000000, + "total_current_value_usd": 3543553344, + "percentage_of_total_supply": 0.618 + }]} +""" +def get_top_public_companies_holding_bitcoin(): + url = f'https://api.coingecko.com/api/v3/companies/public_treasury/bitcoin' + response = requests.get(url) + response.raise_for_status() + result = response.json()['companies'] + return result + + +""" +Get public companies ethereum holdings (Ordered by total holdings descending) +Response in the format: +{ + "total_holdings": 174374.4658, + "total_value_usd": 4764147923.454023, + "market_cap_dominance": 0.9, + "companies": [ + { + "name": "MicroStrategy Inc.", + "symbol": "NASDAQ:MSTR", + "country": "US", + "total_holdings": 129699, + "total_entry_value_usd": 3975000000, + "total_current_value_usd": 3543553344, + "percentage_of_total_supply": 0.618 + }]} +""" +def get_top_public_companies_holding_eth(): + url = f'https://api.coingecko.com/api/v3/companies/public_treasury/ethereum' + response = requests.get(url) + response.raise_for_status() + result = response.json()['companies'] + return result + diff --git a/knowledge_base/widgets.txt b/knowledge_base/widgets.txt index 0708b023..9c95907d 100644 --- a/knowledge_base/widgets.txt +++ b/knowledge_base/widgets.txt @@ -141,6 +141,50 @@ Required parameters: Return value description: -JSON object with trait names and values of the NFT asset --- +Widget magic command: <|fetch-nft-list-order-by-trading-volume-native-token()|> +Description of widget: List all supported NFT, ordered by 24h trading volume of native token +Connected wallet required: no +--- +Widget magic command: <|fetch-nft-list-order-by-floor-price()|> +Description of widget: List all supported NFT, ordered by floor price of native token +Connected wallet required: no +--- +Widget magic command: <|fetch-nft-list-order-by-market-cap-native-token()|> +Description of widget: List all supported NFT, ordered by market cap of native token +Connected wallet required: no +--- +Widget magic command: <|fetch-nft-list-order-by-market-cap-usd()|> +Description of widget: List all supported NFT, ordered by market cap of USD +Connected wallet required: no +--- +Widget magic command: <|fetch-top-searched-token()|> +Description of widget: Top-7 trending coins on CoinGecko as searched by users in the last 24 hours (Ordered by most popular first) +Connected wallet required: no +--- +Widget magic command: <|fetch-defi-market-cap()|> +Description of widget: Get Defi Market Cap +Connected wallet required: no +--- +Widget magic command: <|fetch-ether-market-cap()|> +Description of widget: Get Ether Market Cap +Connected wallet required: no +--- +Widget magic command: <|fetch-trading-volume-last-24h()|> +Description of widget: Get Trading Volume in the last 24h +Connected wallet required: no +--- +Widget magic command: <|fetch-top-coin-volume()|> +Description of widget: Get Top Coin Volume +Connected wallet required: no +--- +Widget magic command: <|fetch-top-public-companies-holding-bitcoin()|> +Description of widget: Get public companies bitcoin holdings (Ordered by total holdings descending) +Connected wallet required: no +--- +Widget magic command: <|fetch-top-public-companies-holding-ether()|> +Description of widget: Get public companies ethereum holdings (Ordered by total holdings descending) +Connected wallet required: no +--- Widget magic command: <|fetch-eval({expression})|> Description of widget: This widget is used when we need to calculate an arbitrary mathematical expression. Connected wallet required: no diff --git a/tools/index_widget.py b/tools/index_widget.py index 6721da50..970be2a5 100644 --- a/tools/index_widget.py +++ b/tools/index_widget.py @@ -18,6 +18,11 @@ from integrations import ( etherscan, defillama, center, ) +from integrations.coingecko import get_top_nft_by_24h_native_token, \ + get_top_nft_by_floor_price_native_token, get_top_nft_by_market_cap_native_token, \ + get_top_nft_by_marketcap_usd, get_top_searched_token_last_24h, get_defi_market_cap, \ + get_eth_market_cap, get_trading_volume_last_24h, get_top_coin_name, \ + get_top_public_companies_holding_bitcoin, get_top_public_companies_holding_eth from .index_lookup import IndexLookupTool @@ -158,6 +163,28 @@ def replace_match(m: re.Match) -> str: return str(fetch_nft_asset(*params)) elif command == 'fetch-nft-asset-traits': return str(fetch_nft_asset_traits(*params)) + elif command == 'fetch-nft-list-order-by-trading-volume-native-token': + return str(get_top_nft_by_24h_native_token()) + elif command == 'fetch-nft-list-order-by-floor-price': + return str(get_top_nft_by_floor_price_native_token()) + elif command == 'fetch-nft-list-order-by-market-cap-native-token': + return str(get_top_nft_by_market_cap_native_token()) + elif command == 'fetch-nft-list-order-by-market-cap-usd': + return str(get_top_nft_by_marketcap_usd()) + elif command == 'fetch-top-searched-token': + return str(get_top_searched_token_last_24h()) + elif command == 'fetch-defi-market-cap': + return str(get_defi_market_cap()) + elif command == 'fetch-ether-market-cap': + return str(get_eth_market_cap()) + elif command == 'fetch-trading-volume-last-24h': + return str(get_trading_volume_last_24h()) + elif command == 'fetch-top-coin-volume': + return str(get_top_coin_name()) + elif command == 'fetch-top-public-companies-holding-bitcoin': + return str(get_top_public_companies_holding_bitcoin()) + elif command == 'fetch-top-public-companies-holding-ether': + return str(get_top_public_companies_holding_eth()) elif command == 'fetch-eval': return str(safe_eval(*params)) elif command == 'fetch-wallet': From d18ff0302c64f1301bc2a3f045eae937b694dc2b Mon Sep 17 00:00:00 2001 From: Ryon Date: Mon, 20 Mar 2023 01:10:10 -0400 Subject: [PATCH 2/2] use statements instead of json --- integrations/coingecko.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/integrations/coingecko.py b/integrations/coingecko.py index 5564d771..1e76cd6b 100644 --- a/integrations/coingecko.py +++ b/integrations/coingecko.py @@ -19,7 +19,8 @@ def get_top_nft_by_24h_native_token(): response = requests.get(url) response.raise_for_status() result = response.json() - return result + return ','.join(["{name} on address {contract_address}".format(name=item['name'],contract_address=item['contract_address']) for item in result]) + """ List all supported NFT, ordered by floor price of native token @@ -40,7 +41,8 @@ def get_top_nft_by_floor_price_native_token(): response = requests.get(url) response.raise_for_status() result = response.json() - return result + return ','.join(["{name} on address {contract_address}".format(name=item['name'],contract_address=item['contract_address']) for item in result]) + """ List all supported NFT, ordered by market cap of native token @@ -61,7 +63,8 @@ def get_top_nft_by_market_cap_native_token(): response = requests.get(url) response.raise_for_status() result = response.json() - return result + return ','.join(["{name} on address {contract_address}".format(name=item['name'],contract_address=item['contract_address']) for item in result]) + """ List all supported NFT, ordered by market cap of USD @@ -82,7 +85,8 @@ def get_top_nft_by_marketcap_usd(): response = requests.get(url) response.raise_for_status() result = response.json() - return result + return ','.join(["{name} on address {contract_address}".format(name=item['name'],contract_address=item['contract_address']) for item in result]) + """ @@ -111,7 +115,8 @@ def get_top_searched_token_last_24h(): response = requests.get(url) response.raise_for_status() result = response.json() - return result + return ','.join(["{name} with symbol {symbol}".format(name=item['item']['name'],symbol=item['item']['symbol']) for item in result]) + """ Get Top 100 Cryptocurrency Global Decentralized Finance(defi) data @@ -187,7 +192,8 @@ def get_top_public_companies_holding_bitcoin(): response = requests.get(url) response.raise_for_status() result = response.json()['companies'] - return result + return ','.join(["{name} with total holding of {total_holdings}".format(name=item['name'],total_holdings=item['total_holdings']) for item in result]) + """ @@ -213,5 +219,6 @@ def get_top_public_companies_holding_eth(): response = requests.get(url) response.raise_for_status() result = response.json()['companies'] - return result + return ','.join(["{name} with total holding of {total_holdings}".format(name=item['name'],total_holdings=item['total_holdings']) for item in result]) +