From 3322b7ca90a158172f08827ece32ab81a78d8586 Mon Sep 17 00:00:00 2001 From: Chirag Tankan <118548447+ChiragTankan@users.noreply.github.com> Date: Fri, 27 Mar 2026 16:25:08 +0530 Subject: [PATCH] Add AI Crypto Price Alert Agent --- Crypto-Price-Alert-Agent/README.md | 13 +++++++++ Crypto-Price-Alert-Agent/agent.py | 33 +++++++++++++++++++++++ Crypto-Price-Alert-Agent/requirements.txt | 2 ++ 3 files changed, 48 insertions(+) create mode 100644 Crypto-Price-Alert-Agent/README.md create mode 100644 Crypto-Price-Alert-Agent/agent.py create mode 100644 Crypto-Price-Alert-Agent/requirements.txt diff --git a/Crypto-Price-Alert-Agent/README.md b/Crypto-Price-Alert-Agent/README.md new file mode 100644 index 00000000..0039b6ca --- /dev/null +++ b/Crypto-Price-Alert-Agent/README.md @@ -0,0 +1,13 @@ +# 🪙 AI Crypto Price Alert Agent + +This agent uses the **Fetch.ai uAgents library** to monitor cryptocurrency prices in real-time. It is designed to help traders or enthusiasts get automated alerts when a specific coin hits a target price. + +## Features +- **Real-time Monitoring:** Fetches data every 60 seconds using the CoinGecko API. +- **Automated Logic:** Compares current price against a user-defined threshold. +- **Fetch.ai Native:** Built using the `uAgents` framework for decentralized communication. + +## How to Run +1. Install dependencies: + ```bash + pip install -r requirements.txt \ No newline at end of file diff --git a/Crypto-Price-Alert-Agent/agent.py b/Crypto-Price-Alert-Agent/agent.py new file mode 100644 index 00000000..1aab7222 --- /dev/null +++ b/Crypto-Price-Alert-Agent/agent.py @@ -0,0 +1,33 @@ +from uagents import Agent, Context +import requests + +# 1. Define your Agent +# Replace "your_seed_phrase" with any random text +crypto_agent = Agent(name="crypto_watcher", seed="Cripto_Watcher_24") + +# 2. Configuration +CRYPTO_ID = "bitcoin" # You can change this to 'ethereum' etc. +THRESHOLD_PRICE = 60000 # Alert if price goes below this + +def get_price(coin_id): + url = f"https://api.coingecko.com/api/v3/simple/price?ids={coin_id}&vs_currencies=usd" + response = requests.get(url) + data = response.json() + return data[coin_id]['usd'] + +@crypto_agent.on_interval(period=60.0) +async def check_price(ctx: Context): + try: + current_price = get_price(CRYPTO_ID) + ctx.logger.info(f"Current {CRYPTO_ID} price: ${current_price}") + + if current_price < THRESHOLD_PRICE: + ctx.logger.info(f"🚨 ALERT: {CRYPTO_ID} is below ${THRESHOLD_PRICE}! Time to buy?") + else: + ctx.logger.info(f"Price is stable above ${THRESHOLD_PRICE}.") + + except Exception as e: + ctx.logger.error(f"Failed to fetch price: {e}") + +if __name__ == "__main__": + crypto_agent.run() \ No newline at end of file diff --git a/Crypto-Price-Alert-Agent/requirements.txt b/Crypto-Price-Alert-Agent/requirements.txt new file mode 100644 index 00000000..fd9d4612 --- /dev/null +++ b/Crypto-Price-Alert-Agent/requirements.txt @@ -0,0 +1,2 @@ +uagents +requests \ No newline at end of file