0xMagnus commited on
Commit
77d6138
·
verified ·
1 Parent(s): a796e10

fix: Hardcoded specific HYPE ticker ID to code

Browse files
Files changed (1) hide show
  1. app.py +14 -27
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
- # 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)}"
 
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)}"