-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhyperliquid_test.py
More file actions
143 lines (108 loc) · 4.42 KB
/
hyperliquid_test.py
File metadata and controls
143 lines (108 loc) · 4.42 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"""
Hyperliquid API Test Script
This script tests the methods available in the hyperliquid-python-sdk and compares them
with the methods being used in the TRbot code.
"""
import inspect
import sys
import logging
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger("hyperliquid_test")
def inspect_module(module_name):
"""
Inspect the module and list all classes and their methods
"""
logger.info(f"Inspecting module: {module_name}")
try:
module = __import__(module_name, fromlist=["*"])
# Get all classes in the module
classes = [obj for name, obj in inspect.getmembers(module) if inspect.isclass(obj)]
for cls in classes:
logger.info(f"Class: {cls.__name__}")
# Get all methods of the class
methods = [name for name, obj in inspect.getmembers(cls) if inspect.isfunction(obj) or inspect.ismethod(obj)]
# Print the methods
for method in methods:
logger.info(f" - {method}")
logger.info("---")
except ImportError as e:
logger.error(f"Failed to import {module_name}: {str(e)}")
def test_info_class():
"""
Test the Info class from hyperliquid-python-sdk
"""
logger.info("Testing Info class")
try:
from hyperliquid.info import Info
# Create an instance
info = Info()
# List available methods
methods = [name for name, obj in inspect.getmembers(info) if callable(obj) and not name.startswith('_')]
logger.info("Available methods in Info class:")
for method in methods:
logger.info(f" - {method}")
# Test specific methods that we're trying to use
test_methods = [
"get_candles",
"get_orderbook",
"get_all_mids_and_funding",
"get_all_mids"
]
logger.info("Testing specific methods:")
for method_name in test_methods:
if method_name in methods:
logger.info(f" - {method_name}: Available")
else:
logger.info(f" - {method_name}: NOT AVAILABLE")
except ImportError as e:
logger.error(f"Failed to import hyperliquid.info.Info: {str(e)}")
except Exception as e:
logger.error(f"Error testing Info class: {str(e)}")
def test_api_calls():
"""
Test actual API calls to verify functionality
"""
logger.info("Testing API calls")
try:
from hyperliquid.info import Info
# Create an instance
info = Info()
# Test getting markets
logger.info("Testing get_markets")
markets = info.get_markets()
logger.info(f"Available markets: {[m.get('name') for m in markets]}")
# Test methods that we need to use (if they exist)
if hasattr(info, 'get_candles'):
logger.info("Testing get_candles for BTC (1h resolution)")
candles = info.get_candles(asset="BTC", resolution=3600)
logger.info(f"Retrieved {len(candles)} candles")
else:
logger.warning("get_candles method not available")
# Check alternative methods that might provide similar functionality
logger.info("Checking alternative methods...")
if hasattr(info, 'get_clob_state'):
logger.info("Testing get_clob_state")
state = info.get_clob_state()
logger.info(f"CLOB state retrieved: {type(state)}")
if hasattr(info, 'get_recent_trades'):
logger.info("Testing get_recent_trades for BTC")
trades = info.get_recent_trades(asset="BTC")
logger.info(f"Retrieved {len(trades)} recent trades")
except Exception as e:
logger.error(f"Error testing API calls: {str(e)}")
if __name__ == "__main__":
logger.info("Starting Hyperliquid SDK test")
# Get Python version
logger.info(f"Python version: {sys.version}")
# Inspect hyperliquid modules
inspect_module("hyperliquid.info")
inspect_module("hyperliquid.exchange")
# Test the Info class specifically
test_info_class()
# Test actual API calls
test_api_calls()
logger.info("Test completed")