-
Notifications
You must be signed in to change notification settings - Fork 68
Add AI Crypto Price Alert Agent #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -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) | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The asynchronous Suggested FixReplace the synchronous Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||||||||||||||||
| data = response.json() | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
| 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() | ||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| uagents | ||
| requests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.