-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample_utils.py
More file actions
38 lines (34 loc) · 1.56 KB
/
example_utils.py
File metadata and controls
38 lines (34 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json
import os
def load_config():
"""
Load configuration from either environment variables or config.json file.
Environment variables take precedence over config file.
"""
# Try environment variables first (more secure)
account_address = os.getenv("HYPERLIQUID_ACCOUNT_ADDRESS")
secret_key = os.getenv("HYPERLIQUID_SECRET_KEY")
is_mainnet = os.getenv("HYPERLIQUID_IS_MAINNET", "true").lower() == "true"
# If environment variables are not set, try config file
if not account_address or not secret_key:
try:
with open("config.json", "r") as f:
config = json.load(f)
account_address = account_address or config.get("account_address")
secret_key = secret_key or config.get("secret_key")
is_mainnet = config.get("is_mainnet", True) if is_mainnet else is_mainnet
except FileNotFoundError:
raise FileNotFoundError(
"Configuration not found. Please either:\n"
"1. Set environment variables: HYPERLIQUID_ACCOUNT_ADDRESS, HYPERLIQUID_SECRET_KEY, HYPERLIQUID_IS_MAINNET\n"
"2. Create a config.json file with your credentials"
)
except json.JSONDecodeError:
raise ValueError("Invalid JSON in config.json file")
if not account_address or not secret_key:
raise ValueError("Account address and secret key are required")
return {
"account_address": account_address,
"secret_key": secret_key,
"is_mainnet": is_mainnet
}