diff --git a/integrations/crypto_market_cap/.gitignore b/integrations/crypto_market_cap/.gitignore new file mode 100644 index 00000000..2eea525d --- /dev/null +++ b/integrations/crypto_market_cap/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/integrations/crypto_market_cap/Readme.md b/integrations/crypto_market_cap/Readme.md new file mode 100644 index 00000000..d381b06d --- /dev/null +++ b/integrations/crypto_market_cap/Readme.md @@ -0,0 +1,66 @@ +# 🪙 CoinMarketCap API Integration with uAgents Hackathon Project + +## 🚀 Introduction + +Welcome to our Hackathon project where we integrate the CoinMarketCap API with Fetch.ai AI Agent technology to create innovative solutions in the world of cryptocurrencies. In this project, we aim to provide real-time data on cryptocurrencies, fetch relevant news, and discover the top trending cryptocurrencies using uAgents. + +## 🎯 Problem Statement + +Our challenge was to integrate the CoinMarketCap API with Fetch.ai AI Agent technology to solve a problem or create something innovative and provide a business useCase of it. We aimed to go beyond simple integration and present creative use cases for this combination of technologies. + +## 📊 CoinMarketCap API + +The CoinMarketCap API is a Text2Text integration that provides comprehensive data on cryptocurrencies. You can learn more about it [here](https://rapidapi.com/zakutynsky/api/CoinMarketCap/). + +## 📥 User Input + +To use our agents, you need to enter a cryptocurrency symbol as input on DeltaV. The symbol should be a valid cryptocurrency symbol like `ETH` for Ethereum, `BTC` for Bitcoin, `XRP` for Ripple, `SOL` for Solana, etc. + +Here's an example of how to enter an input: + +1. Open DeltaV. +2. Select the agent you want to use (CryptoDataAgent, CryptoNewsAgent, or TrendingCryptoAgent). +3. In the input field, enter the cryptocurrency symbol. For example, if you want data on Ethereum, enter `ETH`. +4. Click on the 'Send' button. + +![Input](./src/images/input.jpg) + +The agent will then fetch and display the data related to the cryptocurrency symbol you entered. + +## 🤖 uAgents Integration + +We integrated the CoinMarketCap API with uAgents to create two agents: + +1. **CryptoDataAgent**: Provides real-time data on the requested cryptocurrency. + +| Name | Symbol | Price | Volume (24h) | Change (24h) | Market Cap | +|----------|--------|------------------|---------------------|--------------|----------------------| +| Bitcoin | BTC | 66863.51170428682| 43620642781.30312 | -4.76221334% | 1315925261517.3535 | +| Ethereum | ETH | 3210.858383837866| 21614062100.60566 | -8.52252725% | 385530857439.1761 | + +![Crypto_data_Output](./src/images/crypto_data.jpg) + +2. **CryptoNewsAgent**: Fetches relevant news articles related to the requested cryptocurrency. + +![Crypto_News_Output](./src/images/news_data.jpg) +![Crpto Article based of the output](./src/images/ethereum.jpg) + +3. **TrendingCryptoAgent**: Identifies the top trending cryptocurrencies globally. + +![Crypto_Recommendation_Output](./src/images/news.jpg) + +## 🎥 Video Demo + +[Recommendation and Crypto_data](http://www.youtube.com/watch?v=1mNh9GcWcNA) + +[News and Crypto_data](https://youtu.be/XD0RHiPqi2s?si=XUVdYDZm_WVguZqO) + +## 💼 BUSINESS USECASE + +Our application is a powerful tool for cryptocurrency portfolio management. It caters to the needs of cryptocurrency investors by providing real-time data for their portfolio cryptocurrencies. By simply entering the symbols of their cryptocurrencies, users can access up-to-the-minute information including price, 24-hour change, and market cap, enabling them to make informed investment decisions. + +In addition to personalized data, our application also offers a recommendation feature. It identifies and displays the top 10 performing cryptocurrencies, providing users with insights into potential investment opportunities in the dynamic crypto market. + +Moreover, our application keeps users abreast of the latest market trends by fetching relevant news about the cryptocurrency market. This feature ensures that users are always informed about the current market scenario, further aiding in their investment strategy. + +In essence, our application serves as a comprehensive, real-time cryptocurrency portfolio management tool, helping users optimize their investment decisions. \ No newline at end of file diff --git a/integrations/crypto_market_cap/src/agents/crypto_data.py b/integrations/crypto_market_cap/src/agents/crypto_data.py new file mode 100644 index 00000000..ce649233 --- /dev/null +++ b/integrations/crypto_market_cap/src/agents/crypto_data.py @@ -0,0 +1,73 @@ +from ai_engine import KeyValue, UAgentResponse, UAgentResponseType +import uuid +from dotenv import load_dotenv +import os +import requests +from pydantic import BaseModel + +class CryptoRequest(BaseModel): + symbols: str + +load_dotenv() + +api_key = os.getenv('X_CMC_PRO_API_KEY') + + + +crypto_protocol = Protocol("Crypto") + +@crypto_protocol.on_message(model=CryptoRequest, replies=UAgentResponse) +async def get_crypto_data(ctx: Context, sender: str, msg: CryptoRequest): + symbols = msg.symbols.replace(" ", "").upper() + url = f"https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol={symbols}" + headers = { + 'Accepts': 'application/json', + 'X-CMC_PRO_API_KEY': api_key, # replace 'your_api_key' with your actual API key + } + try: + ctx.logger.info(f"Attempting to fetch data for {msg.symbols}") + crypto_data = requests.get(url, headers=headers) + crypto_data.raise_for_status() + data = crypto_data.json() + + # Extract specific fields from the JSON response and format them as a string + text_data = "" + for symbol, crypto in data['data'].items(): + name = crypto['name'] + price = crypto['quote']['USD']['price'] + volume_24h = crypto['quote']['USD']['volume_24h'] + percent_change_24h = crypto['quote']['USD']['percent_change_24h'] + market_cap = crypto['quote']['USD']['market_cap'] + + text_data += f"Name: {name}, Symbol: {symbol}, Price: {price}, Volume (24h): {volume_24h}, Change (24h): {percent_change_24h}%, Market Cap: {market_cap}\n" + + ctx.logger.info(text_data) + request_id = str(uuid.uuid4()) + ctx.logger.info("test1") + + await ctx.send( + sender, + UAgentResponse( + message=text_data, + type=UAgentResponseType.FINAL, + request_id=request_id + ), + ) + + # Ask the user if they also want to see the top performing cryptocurrencies + await ctx.send( + sender, + UAgentResponse( + message="Do you also want to see the top performing cryptocurrencies?", + type=UAgentResponseType.QUESTION, + request_id=request_id, + options=["Yes", "No"] + ), + ) + + except Exception as exc: + ctx.logger.info(f"Error during Crypto Data retrieval: {exc}") + return None + +crypto_agent = Agent() +crypto_agent.include(crypto_protocol) \ No newline at end of file diff --git a/integrations/crypto_market_cap/src/agents/news.py b/integrations/crypto_market_cap/src/agents/news.py new file mode 100644 index 00000000..046326f8 --- /dev/null +++ b/integrations/crypto_market_cap/src/agents/news.py @@ -0,0 +1,51 @@ +from ai_engine import KeyValue, UAgentResponse, UAgentResponseType +import uuid +import requests +import os +from dotenv import load_dotenv + +load_dotenv() +class TopGrowthRequest(Model): + pass + +crypto_protocol = Protocol("Crypto") + +@crypto_protocol.on_message(model=TopGrowthRequest, replies=UAgentResponse) +async def get_top_growth(ctx: Context, sender: str, msg: TopGrowthRequest): + try: + # Fetch news data + api_key = os.getenv('NEWS_API_KEY') + news_url = "https://newsdata.io/api/1/news?apikey={api_key}&q=BTC,ETH&language=en" + ctx.logger.info("Attempting to fetch news data...") + news_data = requests.get(news_url) + news_data.raise_for_status() + data = news_data.json() + ctx.logger.info(data) + + # Extract titles and links of the top 5 articles + articles = data['results'][:5] + text_data = "" + for article in articles: + title = article['title'] + link = article['link'] + + text_data += f"Title: {title}\nLink: {link}\n\n" + + ctx.logger.info(text_data) + # Send the response + request_id = str(uuid.uuid4()) + await ctx.send( + sender, + UAgentResponse( + message=text_data, + type=UAgentResponseType.FINAL, + request_id=request_id + ), + ) + + except Exception as exc: + ctx.logger.error(f"Error during news data retrieval: {exc}") + return None + +agent = Agent() +agent.include(crypto_protocol) \ No newline at end of file diff --git a/integrations/crypto_market_cap/src/agents/recommendation.py b/integrations/crypto_market_cap/src/agents/recommendation.py new file mode 100644 index 00000000..f3dcaf1a --- /dev/null +++ b/integrations/crypto_market_cap/src/agents/recommendation.py @@ -0,0 +1,66 @@ +from ai_engine import KeyValue, UAgentResponse, UAgentResponseType +import uuid +import requests +from dotenv import load_dotenv +import os + +load_dotenv() + +api_key = os.getenv('X_CMC_PRO_API_KEY') + +class TopGrowthRequest(Model): + pass + +crypto_protocol = Protocol("Crypto") + +@crypto_protocol.on_message(model=TopGrowthRequest, replies=UAgentResponse) +async def get_top_growth(ctx: Context, sender: str, msg: TopGrowthRequest): + """Fetch top growing cryptocurrencies from CoinMarketCap API.""" + url = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest" + headers = { + 'Accepts': 'application/json', + 'X-CMC_PRO_API_KEY': api_key, # replace 'your_api_key' with your actual API key + } + try: + ctx.logger.info(f"Attempting to fetch top growing cryptocurrencies") + crypto_data = requests.get(url, headers=headers) + crypto_data.raise_for_status() + data = crypto_data.json() + + # Sort the cryptocurrencies by the percentage change in the last 24 hours in descending order + sorted_cryptos = sorted(data['data'], key=lambda crypto: crypto['quote']['USD']['percent_change_24h'], reverse=True) + + # Get the top 10 cryptocurrencies + top_10_cryptos = sorted_cryptos[:10] + + # Format the data for display + text_data = "" + for crypto in top_10_cryptos: + name = crypto['name'] + symbol = crypto['symbol'] + price = crypto['quote']['USD']['price'] + volume_24h = crypto['quote']['USD']['volume_24h'] + percent_change_24h = crypto['quote']['USD']['percent_change_24h'] + market_cap = crypto['quote']['USD']['market_cap'] + + text_data += f"Name: {name}, Symbol: {symbol}, Price: {price}, Volume (24h): {volume_24h}, Change (24h): {percent_change_24h}%, Market Cap: {market_cap}\n" + + ctx.logger.info(text_data) + request_id = str(uuid.uuid4()) + ctx.logger.info("test1") + + await ctx.send( + sender, + UAgentResponse( + message=text_data, + type=UAgentResponseType.FINAL, + request_id=request_id + ), + ) + + + except Exception as exc: + ctx.logger.info(f"Error during Crypto Data retrieval: {exc}") + return None + +agent.include(crypto_protocol) \ No newline at end of file diff --git a/integrations/crypto_market_cap/src/images/crypto_data.jpg b/integrations/crypto_market_cap/src/images/crypto_data.jpg new file mode 100644 index 00000000..14816f04 Binary files /dev/null and b/integrations/crypto_market_cap/src/images/crypto_data.jpg differ diff --git a/integrations/crypto_market_cap/src/images/ethereum.jpg b/integrations/crypto_market_cap/src/images/ethereum.jpg new file mode 100644 index 00000000..379173f8 Binary files /dev/null and b/integrations/crypto_market_cap/src/images/ethereum.jpg differ diff --git a/integrations/crypto_market_cap/src/images/input.jpg b/integrations/crypto_market_cap/src/images/input.jpg new file mode 100644 index 00000000..cf135ea8 Binary files /dev/null and b/integrations/crypto_market_cap/src/images/input.jpg differ diff --git a/integrations/crypto_market_cap/src/images/news.jpg b/integrations/crypto_market_cap/src/images/news.jpg new file mode 100644 index 00000000..b50fed51 Binary files /dev/null and b/integrations/crypto_market_cap/src/images/news.jpg differ diff --git a/integrations/crypto_market_cap/src/images/news_data.jpg b/integrations/crypto_market_cap/src/images/news_data.jpg new file mode 100644 index 00000000..43648e2f Binary files /dev/null and b/integrations/crypto_market_cap/src/images/news_data.jpg differ diff --git a/integrations/crypto_market_cap/src/videos/WhatsApp Video 2024-04-13 at 07.50.54_a3fb4d172323.mp4 b/integrations/crypto_market_cap/src/videos/WhatsApp Video 2024-04-13 at 07.50.54_a3fb4d172323.mp4 new file mode 100644 index 00000000..9fb25086 Binary files /dev/null and b/integrations/crypto_market_cap/src/videos/WhatsApp Video 2024-04-13 at 07.50.54_a3fb4d172323.mp4 differ diff --git a/integrations/crypto_market_cap/src/videos/WhatsApp Video 2024-04-13 at 07.51.04_9fc3e341.mp4 b/integrations/crypto_market_cap/src/videos/WhatsApp Video 2024-04-13 at 07.51.04_9fc3e341.mp4 new file mode 100644 index 00000000..6466313e Binary files /dev/null and b/integrations/crypto_market_cap/src/videos/WhatsApp Video 2024-04-13 at 07.51.04_9fc3e341.mp4 differ