Spaces:
Sleeping
Sleeping
Replaced Binance API with CoinGecko
Browse files
app.py
CHANGED
|
@@ -10,32 +10,28 @@ from Gradio_UI import GradioUI
|
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
def get_crypto_price(symbol: str) -> str:
|
| 13 |
-
"""
|
| 14 |
-
Args:
|
| 15 |
-
symbol: The cryptocurrency symbol (e.g., 'BTC', 'ETH', 'XRP').
|
| 16 |
-
"""
|
| 17 |
try:
|
| 18 |
symbol = symbol.upper()
|
| 19 |
-
|
| 20 |
-
response = requests.get(
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
data = response.json()
|
| 23 |
|
| 24 |
-
if '
|
| 25 |
-
price = "{:,.2f}".format(
|
| 26 |
-
return f"
|
| 27 |
-
else:
|
| 28 |
-
return f"❌ Error: {data.get('msg', 'Unknown error')}"
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
error_msg = data.get('msg', 'Invalid cryptocurrency symbol')
|
| 33 |
-
return f"❌ {error_msg} - Try symbols like BTC, ETH, or SOL"
|
| 34 |
-
return f"❌ HTTP Error: {str(e)}"
|
| 35 |
-
except requests.exceptions.RequestException as e:
|
| 36 |
-
return f"🌐 Network Error: {str(e)}"
|
| 37 |
except Exception as e:
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
@tool
|
| 41 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
def get_crypto_price(symbol: str) -> str:
|
| 13 |
+
"""Get cryptocurrency price with basic error handling"""
|
|
|
|
|
|
|
|
|
|
| 14 |
try:
|
| 15 |
symbol = symbol.upper()
|
| 16 |
+
# Using CoinGecko's simple API (no key needed)
|
| 17 |
+
response = requests.get(
|
| 18 |
+
f"https://api.coingecko.com/api/v3/simple/price?ids={symbol.lower()}&vs_currencies=usd",
|
| 19 |
+
timeout=3
|
| 20 |
+
)
|
| 21 |
data = response.json()
|
| 22 |
|
| 23 |
+
if symbol.lower() in data and 'usd' in data[symbol.lower()]:
|
| 24 |
+
price = "{:,.2f}".format(data[symbol.lower()]['usd'])
|
| 25 |
+
return f"Current {symbol} price: ${price}"
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
return f"Could not find price for {symbol} (try BTC/ETH/SOL)"
|
| 28 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
except Exception as e:
|
| 30 |
+
# Fallback to hardcoded prices if API fails
|
| 31 |
+
default_prices = {'BTC': 63000, 'ETH': 3500, 'SOL': 150}
|
| 32 |
+
if symbol in default_prices:
|
| 33 |
+
return f"{symbol} price unavailable - Last known: ${default_prices[symbol]:,}"
|
| 34 |
+
return f"Price check failed for {symbol}"
|
| 35 |
|
| 36 |
@tool
|
| 37 |
def get_current_time_in_timezone(timezone: str) -> str:
|