Spaces:
Sleeping
Sleeping
fix: Hardcoded specific HYPE ticker ID to code
Browse files
app.py
CHANGED
|
@@ -40,36 +40,23 @@ def get_hype_price() -> str:
|
|
| 40 |
url = "https://api.hyperliquid.xyz/info"
|
| 41 |
headers = {"Content-Type": "application/json"}
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
|
| 45 |
-
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
#
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
break
|
| 56 |
|
| 57 |
-
|
| 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 {
|
| 73 |
|
| 74 |
except Exception as e:
|
| 75 |
return f"Error fetching Hyperliquid price: {str(e)}"
|
|
|
|
| 40 |
url = "https://api.hyperliquid.xyz/info"
|
| 41 |
headers = {"Content-Type": "application/json"}
|
| 42 |
|
| 43 |
+
# Request payload for current prices
|
| 44 |
+
payload = {
|
| 45 |
+
"type": "allMids"
|
| 46 |
+
}
|
| 47 |
|
| 48 |
+
response = requests.post(url, headers=headers, json=payload)
|
| 49 |
+
|
| 50 |
+
if response.status_code == 200:
|
| 51 |
+
data = response.json()
|
| 52 |
+
# HYPE is at index 150, so we look for "@150" in the response
|
| 53 |
+
if "@150" in data:
|
| 54 |
+
price = data["@150"]
|
| 55 |
+
return f"Current HYPE/USDC price on Hyperliquid is: {price} USDC"
|
|
|
|
| 56 |
|
| 57 |
+
return "Error: HYPE price not found in current mids"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
else:
|
| 59 |
+
return f"Error: API request failed with status code {response.status_code}"
|
| 60 |
|
| 61 |
except Exception as e:
|
| 62 |
return f"Error fetching Hyperliquid price: {str(e)}"
|