Created
August 22, 2024 10:59
-
-
Save deependersingla/ea78f2b86d6e2d3d0946f97ba01cc12b to your computer and use it in GitHub Desktop.
hyperspots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_metadata(body_type): | |
api_url = 'https://api.hyperliquid.xyz/info' | |
headers = { | |
'Content-Type': 'application/json', | |
} | |
body = { | |
"type": body_type | |
} | |
response = requests.post(api_url, json=body, headers=headers) | |
data = response.json() | |
return data | |
def get_size_spot_dict_meta(): | |
spot_metadata = get_metadata("spotMeta") | |
universe_dict = {} | |
for item in spot_metadata['universe']: | |
key = item['tokens'][0] | |
value = item['name'] | |
universe_dict[key] = value | |
size_dict_spot = {} | |
token_info = {item['index']: { | |
'szDecimals': item['szDecimals'], | |
'weiDecimals': item['weiDecimals'], | |
'name': item['name'], | |
"token": item["index"] | |
} for item in spot_metadata['tokens']} | |
for key, value in universe_dict.items(): | |
size_dict_spot[value] = token_info[key] | |
return size_dict_spot | |
def spot_universal_dict(): | |
universal_dict = {0: "USDC", 1: 'PURR/USDC', 2: '@1', 3: '@2', 4: '@3', 5: '@4', 6: '@5', 7: '@6', 8: '@7', 9: '@8', 10: '@9', 11: '@10', 12: '@11', 13: '@12', 14: '@13', 15: '@14', 16: '@15', 17: '@16', 18: '@17', 19: '@18', 20: '@19', 26: '@20', 24: '@21', 29: '@22', 27: '@23', 30: '@24', 23: '@25', 28: '@26', 31: '@27', 22: '@28', 34: '@29', 32: '@30', 35: '@31', 33: '@32', 37: '@33', 38: '@34', 25: '@35', 40: '@36', 42: '@37', 36: '@38', 45: '@39', 46: '@40'} | |
return universal_dict | |
def get_spot_balance(account_address): | |
data = global_info.spot_user_state(account_address) | |
universal_dict = spot_universal_dict() | |
new_dict = {} | |
for item in data['balances']: | |
if item['token'] in universal_dict: | |
new_dict[universal_dict[item['token']]] = float(item['total']) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment