Files
hyper/check_wtioil.py

81 lines
3.2 KiB
Python

"""
Script to check if WTIOIL/CLUSD is available on Hyperliquid and add it to monitoring.
"""
import json
import logging
import requests
from hyperliquid.info import Info
from hyperliquid.utils import constants
from logging_utils import setup_logging
def check_and_add_wtioil():
"""Check if WTIOIL is available on Hyperliquid and add it to the precision file."""
setup_logging('normal', 'WTIOILChecker')
coin_name = "xyz:CLUSD" # Full HIP-3 format
alternative_names = ["WTIOIL", "CLUSD", "WTI"]
logging.info(f"Checking if {coin_name} is available on Hyperliquid...")
# Try direct HTTP API call for all mids
try:
url = 'https://api.hyperliquid.xyz/info'
payload = {"type": "allMids"}
response = requests.post(url, json=payload, timeout=10)
if response.status_code == 200:
result = response.json()
all_mids = result.get('mids', {})
print(f"\nTotal coins available: {len(all_mids)}")
# Look for oil-related coins
found = False
for name in all_mids.keys():
if 'oil' in name.lower() or 'wti' in name.lower() or 'cl' in name.lower() or 'xyz' in name.lower():
print(f"Found: {name} - Price: {all_mids[name]}")
found = True
if not found:
print("No oil-related coins found in all_mids.")
print("\nTrying alternative coin names...")
for alt_name in alternative_names:
try:
l2_payload = [{"type": "l2Book", "coin": alt_name}]
l2_response = requests.post(url, json=l2_payload, timeout=10)
if l2_response.status_code == 200:
l2_data = l2_response.json()
print(f"[OK] {alt_name} is available on Hyperliquid!")
print(f" L2 data: {l2_data}")
else:
print(f"[FAIL] {alt_name} not available (HTTP {l2_response.status_code})")
except Exception as e:
print(f"[ERROR] {alt_name}: {e}")
else:
print(f"Failed to get allMids: HTTP {response.status_code}")
print(f"Response: {response.text[:200]}")
except Exception as e:
logging.error(f"Error checking availability: {e}")
return
# Try to add to coin_precision.json
precision_file = "_data/coin_precision.json"
try:
with open(precision_file, 'r') as f:
precision_data = json.load(f)
# Add WTIOIL if not present
if coin_name not in precision_data:
precision_data[coin_name] = 2 # Default precision for commodities
with open(precision_file, 'w') as f:
json.dump(precision_data, f, indent=4, sort_keys=True)
logging.info(f"Added {coin_name} to {precision_file} with precision 2")
else:
logging.info(f"{coin_name} already exists in {precision_file}")
except Exception as e:
logging.error(f"Error updating precision file: {e}")
if __name__ == "__main__":
check_and_add_wtioil()