0xMagnus commited on
Commit
4b957d0
·
verified ·
1 Parent(s): a9046c3

fix: simplified approach and pulling HYPE price from perps market instead

Browse files
Files changed (1) hide show
  1. app.py +5 -15
app.py CHANGED
@@ -42,30 +42,20 @@ def get_hype_price() -> str:
42
  "Content-Type": "application/json"
43
  }
44
 
45
- # Request payload for spot market data
46
  payload = {
47
- "type": "spotMetaAndAssetCtxs"
48
  }
49
 
50
  response = requests.post(url, headers=headers, json=payload)
51
 
52
  if response.status_code == 200:
53
  data = response.json()
54
- market_data = data[1] # Market data is in the second array element
55
 
56
- for market in market_data:
57
- if market.get("coin") == "@150": # HYPE's index
58
- mark_price = float(market["markPx"])
59
- mid_price = float(market["midPx"])
60
- volume = float(market["dayNtlVlm"])
61
-
62
- # Format with 2 decimal places as per szDecimals
63
- return f"HYPE/USDC Price:\n" \
64
- f"Mark Price: {mark_price:.2f} USDC\n" \
65
- f"Mid Price: {mid_price:.2f} USDC\n" \
66
- f"24h Volume: {volume:.2f} USDC"
67
 
68
- return "Error: HYPE market not found in response"
69
  else:
70
  return f"Error: API request failed with status code {response.status_code}"
71
 
 
42
  "Content-Type": "application/json"
43
  }
44
 
 
45
  payload = {
46
+ "type": "allMids"
47
  }
48
 
49
  response = requests.post(url, headers=headers, json=payload)
50
 
51
  if response.status_code == 200:
52
  data = response.json()
 
53
 
54
+ if "HYPE" in data:
55
+ price = float(data["HYPE"])
56
+ return f"Current HYPE/USDC price: {price:.4f} USDC"
 
 
 
 
 
 
 
 
57
 
58
+ return "Error: HYPE price not found in response"
59
  else:
60
  return f"Error: API request failed with status code {response.status_code}"
61