Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,34 +37,39 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 37 |
def get_hype_price() -> str:
|
| 38 |
"""A tool that fetches the current HYPE/USDC price from Hyperliquid Spot market."""
|
| 39 |
try:
|
| 40 |
-
# API endpoint
|
| 41 |
url = "https://api.hyperliquid.xyz/info"
|
|
|
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
}
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
# Make the POST request
|
| 54 |
-
response = requests.post(url, headers=headers, json=payload)
|
| 55 |
-
|
| 56 |
-
if response.status_code == 200:
|
| 57 |
-
data = response.json()
|
| 58 |
|
| 59 |
-
#
|
| 60 |
-
for
|
| 61 |
-
if
|
| 62 |
-
|
| 63 |
-
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
else:
|
| 67 |
-
return f"Error: API request failed with status code {
|
| 68 |
|
| 69 |
except Exception as e:
|
| 70 |
return f"Error fetching Hyperliquid price: {str(e)}"
|
|
|
|
| 37 |
def get_hype_price() -> str:
|
| 38 |
"""A tool that fetches the current HYPE/USDC price from Hyperliquid Spot market."""
|
| 39 |
try:
|
|
|
|
| 40 |
url = "https://api.hyperliquid.xyz/info"
|
| 41 |
+
headers = {"Content-Type": "application/json"}
|
| 42 |
|
| 43 |
+
# First, get spot meta to find HYPE's index
|
| 44 |
+
meta_payload = {"type": "spotMeta"}
|
| 45 |
+
meta_response = requests.post(url, headers=headers, json=meta_payload)
|
|
|
|
| 46 |
|
| 47 |
+
if meta_response.status_code == 200:
|
| 48 |
+
meta_data = meta_response.json()
|
| 49 |
+
hype_index = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
# Find HYPE's index in the universe
|
| 52 |
+
for token in meta_data["universe"]:
|
| 53 |
+
if token["name"] == "HYPE":
|
| 54 |
+
hype_index = token["index"]
|
| 55 |
+
break
|
| 56 |
|
| 57 |
+
if hype_index is not None:
|
| 58 |
+
# Now get all mids
|
| 59 |
+
mids_payload = {"type": "allMids"}
|
| 60 |
+
mids_response = requests.post(url, headers=headers, json=mids_payload)
|
| 61 |
+
|
| 62 |
+
if mids_response.status_code == 200:
|
| 63 |
+
mids_data = mids_response.json()
|
| 64 |
+
token_key = f"@{hype_index}"
|
| 65 |
+
|
| 66 |
+
if token_key in mids_data:
|
| 67 |
+
price = mids_data[token_key]
|
| 68 |
+
return f"Current HYPE/USDC price on Hyperliquid is: {price} USDC"
|
| 69 |
+
|
| 70 |
+
return "Error: HYPE market not found in current mids"
|
| 71 |
else:
|
| 72 |
+
return f"Error: API request failed with status code {meta_response.status_code}"
|
| 73 |
|
| 74 |
except Exception as e:
|
| 75 |
return f"Error fetching Hyperliquid price: {str(e)}"
|