Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,11 +12,11 @@ def get_btc_price() -> str:
|
|
| 12 |
url = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd"
|
| 13 |
response = requests.get(url)
|
| 14 |
if response.status_code != 200:
|
| 15 |
-
return
|
| 16 |
data = response.json()
|
| 17 |
price = data.get('bitcoin', {}).get('usd')
|
| 18 |
if price is None:
|
| 19 |
-
return
|
| 20 |
return f"The current Bitcoin price is ${price:.2f} USD."
|
| 21 |
|
| 22 |
@tool
|
|
@@ -29,7 +29,7 @@ def get_btc_historical_prices(days: int = 30) -> str:
|
|
| 29 |
url = f"https://api.coingecko.com/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days={days}&interval=daily"
|
| 30 |
response = requests.get(url)
|
| 31 |
if response.status_code != 200:
|
| 32 |
-
return
|
| 33 |
data = response.json()
|
| 34 |
prices = data.get('prices', [])
|
| 35 |
df = pd.DataFrame(prices, columns=['timestamp', 'price'])
|
|
|
|
| 12 |
url = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd"
|
| 13 |
response = requests.get(url)
|
| 14 |
if response.status_code != 200:
|
| 15 |
+
return "Failed to fetch Bitcoin price"
|
| 16 |
data = response.json()
|
| 17 |
price = data.get('bitcoin', {}).get('usd')
|
| 18 |
if price is None:
|
| 19 |
+
return "Bitcoin price not found"
|
| 20 |
return f"The current Bitcoin price is ${price:.2f} USD."
|
| 21 |
|
| 22 |
@tool
|
|
|
|
| 29 |
url = f"https://api.coingecko.com/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days={days}&interval=daily"
|
| 30 |
response = requests.get(url)
|
| 31 |
if response.status_code != 200:
|
| 32 |
+
return "Failed to fetch historical Bitcoin prices"
|
| 33 |
data = response.json()
|
| 34 |
prices = data.get('prices', [])
|
| 35 |
df = pd.DataFrame(prices, columns=['timestamp', 'price'])
|