Skip to content

Commit c25ecb6

Browse files
committed
Version 0.2.1
1 parent cf2024d commit c25ecb6

File tree

8 files changed

+257
-43
lines changed

8 files changed

+257
-43
lines changed

hyperliquid/info.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,11 @@ def funding_history(self, coin: str, startTime: int, endTime: Optional[int] = No
198198

199199
def user_funding_history(self, user: str, startTime: int, endTime: Optional[int] = None) -> Any:
200200
"""Retrieve a user's funding history
201-
202201
POST /info
203-
204202
Args:
205203
user (str): Address of the user in 42-character hexadecimal format.
206204
startTime (int): Start time in milliseconds, inclusive.
207205
endTime (int, optional): End time in milliseconds, inclusive. Defaults to current time.
208-
209206
Returns:
210207
List[Dict]: A list of funding history records, where each record contains:
211208
- user (str): User address.
@@ -214,12 +211,8 @@ def user_funding_history(self, user: str, startTime: int, endTime: Optional[int]
214211
- endTime (int): Unix timestamp of the end time in milliseconds.
215212
"""
216213
if endTime is not None:
217-
return self.post(
218-
"/info", {"type": "userFunding", "user": user, "startTime": startTime, "endTime": endTime}
219-
)
220-
return self.post(
221-
"/info", {"type": "userFunding", "user": user, "startTime": startTime}
222-
)
214+
return self.post("/info", {"type": "userFunding", "user": user, "startTime": startTime, "endTime": endTime})
215+
return self.post("/info", {"type": "userFunding", "user": user, "startTime": startTime})
223216

224217
def l2_snapshot(self, coin: str) -> Any:
225218
"""Retrieve L2 snapshot for a given coin

poetry.lock

Lines changed: 149 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
55

66
[tool.poetry]
77
name = "hyperliquid-python-sdk"
8-
version = "0.2.0"
8+
version = "0.2.1"
99
description = "SDK for Hyperliquid API trading with Python."
1010
readme = "README.md"
1111
authors = ["Hyperliquid <[email protected]>"]
@@ -43,7 +43,7 @@ eth-abi = "^3.0.1"
4343
eth-account = "^0.8.0"
4444
websocket-client = "^1.5.1"
4545
requests = "^2.31.0"
46-
msgpack-python = "^0.5.6"
46+
msgpack = "^1.0.5"
4747

4848
[tool.poetry.dev-dependencies]
4949
python = "3.10.10"

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ eth-typing==3.2.0 ; python_version >= "3.7" and python_version < "4"
1313
eth-utils==2.2.0 ; python_version >= "3.7" and python_version < "4"
1414
hexbytes==0.3.1 ; python_version >= "3.7" and python_version < "4"
1515
idna==3.4 ; python_version >= "3.7" and python_version < "4.0"
16-
msgpack-python==0.5.6 ; python_version >= "3.7" and python_version < "4.0"
16+
msgpack==1.0.5 ; python_version >= "3.7" and python_version < "4.0"
1717
parsimonious==0.8.1 ; python_version >= "3.7" and python_version < "4"
1818
pycryptodome==3.18.0 ; python_version >= "3.7" and python_version < "4"
1919
requests==2.31.0 ; python_version >= "3.7" and python_version < "4.0"
2020
rlp==3.0.0 ; python_version >= "3.7" and python_version < "4"
2121
six==1.16.0 ; python_version >= "3.7" and python_version < "4"
22-
toolz==0.12.0 ; python_version >= "3.7" and python_version < "4" and (implementation_name == "pypy" or implementation_name == "cpython")
22+
toolz==0.12.0 ; python_version >= "3.7" and python_version < "4" and implementation_name == "pypy" or python_version >= "3.7" and python_version < "4" and implementation_name == "cpython"
2323
urllib3==1.26.16 ; python_version >= "3.7" and python_version < "4.0"
2424
websocket-client==1.6.1 ; python_version >= "3.7" and python_version < "4.0"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
interactions:
2+
- request:
3+
body: '{"type": "userFunding", "user": "0xb7b6f3cea3f66bf525f5d8f965f6dbf6d9b017b2",
4+
"startTime": 1681923833000, "endTime": 1682010233000}'
5+
headers:
6+
Accept:
7+
- '*/*'
8+
Accept-Encoding:
9+
- gzip, deflate
10+
Connection:
11+
- keep-alive
12+
Content-Length:
13+
- '131'
14+
Content-Type:
15+
- application/json
16+
User-Agent:
17+
- python-requests/2.31.0
18+
method: POST
19+
uri: https://api.hyperliquid.xyz/info
20+
response:
21+
body:
22+
string: '[{"delta":{"coin":"APE","fundingRate":"-0.00029319","nSamples":3,"szi":"40.13333333","type":"funding","usdc":"0.145796"},"hash":"0xe3f4c682738ae2ee62510a7282db05c55f1b2032b6a366be9af99d6c809ac899","time":1681948800000},{"delta":{"coin":"ARB","fundingRate":"0.0001","nSamples":3,"szi":"-6091.03333333","type":"funding","usdc":"2.694388"},"hash":"0x9c8402aa5bf03018d1985574aa4e0624e3e7a6e17356ca443cc52f156809f2f7","time":1681948800000},{"delta":{"coin":"ATOM","fundingRate":"0.00001378","nSamples":3,"szi":"-115.77333333","type":"funding","usdc":"0.056134"},"hash":"0xb3e8c970a166343922cf6da328116923ccda63699202c8659e8f31f50ae4e7c5","time":1681948800000},{"delta":{"coin":"AVAX","fundingRate":"0.0001","nSamples":3,"szi":"100.86333333","type":"funding","usdc":"-0.572915"},"hash":"0x5babee5f9e95b33e153dd81fbc4bb82a887687eac7cc8dce24a65107d17774d2","time":1681948800000},{"delta":{"coin":"BNB","fundingRate":"0.0001","nSamples":3,"szi":"0.31933333","type":"funding","usdc":"-0.030851"},"hash":"0x07006d552b857cf807ef0f29b2985708803b95b64bdeff6b94ca2f8baa476a7d","time":1681948800000},{"delta":{"coin":"BTC","fundingRate":"0.00010081","nSamples":3,"szi":"-0.68582","type":"funding","usdc":"5.950454"},"hash":"0xabf969efeb47a3a53180729ca55352862084d5842f8dc7f0d73806a308adf773","time":1681948800000},{"delta":{"coin":"DOGE","fundingRate":"0.00000201","nSamples":3,"szi":"18286.33333333","type":"funding","usdc":"-0.007328"},"hash":"0x0a285d0126678751b3601bee2d2ada8bff9bdc1b2a51fd9a2b31b74f83564066","time":1681948800000},{"delta":{"coin":"DYDX","fundingRate":"0.00009324","nSamples":3,"szi":"237.26666667","type":"funding","usdc":"-0.184592"},"hash":"0x1859f2bc14318c889d55dfc2e5f3b2fcc8263566f5eaa0ddef2c810d27e6c920","time":1681948800000},{"delta":{"coin":"ETH","fundingRate":"0.0001","nSamples":3,"szi":"-5.8509","type":"funding","usdc":"3.414774"},"hash":"0x79a992fa66478b7bed080097eeef0992141cc220080c85372432221e4d9a76d3","time":1681948800000},{"delta":{"coin":"LTC","fundingRate":"0.00003905","nSamples":3,"szi":"-3.72","type":"funding","usdc":"0.039392"},"hash":"0x8a541f3fbdeaf92edfcd6e8739f45a4c8ce8137d393dd651b3d6515a9571bfaa","time":1681948800000},{"delta":{"coin":"MATIC","fundingRate":"-0.00005673","nSamples":3,"szi":"2553.1","type":"funding","usdc":"0.462944"},"hash":"0x848a9722fd2fc6a99a374ff2f4b03c154c4a1e4b459fbef3f130ebe2cf97018d","time":1681948800000},{"delta":{"coin":"OP","fundingRate":"0.0001","nSamples":3,"szi":"124.83333333","type":"funding","usdc":"-0.094193"},"hash":"0xae9c1bb01e34281c1550e4619fb587141f1015786150c4e859a464a7ef07aed1","time":1681948800000},{"delta":{"coin":"SOL","fundingRate":"0.0001","nSamples":3,"szi":"-3.48","type":"funding","usdc":"0.023856"},"hash":"0x19f78c806cdd1b1e298899a52e9ff1b66e4d151f2973d42220dd3bebe7043dcf","time":1681948800000}]'
23+
headers:
24+
access-control-allow-origin:
25+
- '*'
26+
access-control-expose-headers:
27+
- '*'
28+
content-length:
29+
- '2796'
30+
content-type:
31+
- application/json
32+
date:
33+
- Tue, 20 Feb 2024 17:42:28 GMT
34+
vary:
35+
- origin
36+
- access-control-request-method
37+
- access-control-request-headers
38+
status:
39+
code: 200
40+
message: OK
41+
version: 1

tests/cassettes/info_test/test_user_funding_history_without_end_time.yaml

Lines changed: 41 additions & 0 deletions
Large diffs are not rendered by default.

tests/info_test.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,33 +93,29 @@ def test_get_candles_snapshot():
9393
def test_user_funding_history_with_end_time():
9494
info = Info(skip_ws=True)
9595
response = info.user_funding_history(
96-
user="0xb7b6f3cea3f66bf525f5d8f965f6dbf6d9b017b2",
97-
startTime=1681923833000,
98-
endTime=1682010233000
96+
user="0xb7b6f3cea3f66bf525f5d8f965f6dbf6d9b017b2", startTime=1681923833000, endTime=1682010233000
9997
)
10098
assert isinstance(response, list), "The answer should be a list"
10199
for record in response:
102-
assert 'delta' in record, "There must be a key 'delta'"
103-
assert 'hash' in record, "There must be a key 'hash'"
104-
assert 'time' in record, "There must be a key 'time'"
105-
delta = record['delta']
106-
for key in ['coin', 'fundingRate', 'szi', 'type', 'usdc']:
100+
assert "delta" in record, "There must be a key 'delta'"
101+
assert "hash" in record, "There must be a key 'hash'"
102+
assert "time" in record, "There must be a key 'time'"
103+
delta = record["delta"]
104+
for key in ["coin", "fundingRate", "szi", "type", "usdc"]:
107105
assert key in delta, f"В 'delta' There must be a key '{key}'"
108-
assert delta['type'] == 'funding', "The type must be 'funding'"
106+
assert delta["type"] == "funding", "The type must be 'funding'"
107+
109108

110109
@pytest.mark.vcr()
111110
def test_user_funding_history_without_end_time():
112111
info = Info(skip_ws=True)
113-
response = info.user_funding_history(
114-
user="0xb7b6f3cea3f66bf525f5d8f965f6dbf6d9b017b2",
115-
startTime=1681923833000
116-
)
112+
response = info.user_funding_history(user="0xb7b6f3cea3f66bf525f5d8f965f6dbf6d9b017b2", startTime=1681923833000)
117113
assert isinstance(response, list), "The answer must be a list"
118114
for record in response:
119-
assert 'delta' in record, "There must be a key 'delta'"
120-
assert 'hash' in record, "There must be a key 'hash'"
121-
assert 'time' in record, "There must be a key 'time'"
122-
delta = record['delta']
123-
for key in ['coin', 'fundingRate', 'szi', 'type', 'usdc']:
115+
assert "delta" in record, "There must be a key 'delta'"
116+
assert "hash" in record, "There must be a key 'hash'"
117+
assert "time" in record, "There must be a key 'time'"
118+
delta = record["delta"]
119+
for key in ["coin", "fundingRate", "szi", "type", "usdc"]:
124120
assert key in delta, f"В 'delta' There must be a '{key}'"
125-
assert delta['type'] == 'funding', "The type must be 'funding'"
121+
assert delta["type"] == "funding", "The type must be 'funding'"

tests/signing_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ def test_l1_action_signing_order_with_cloid_matches():
104104
timestamp,
105105
True,
106106
)
107-
assert signature_mainnet["r"] == "0xb3bb4fb9ccc13c11ff5e0e387bbf181c6542a0b62a5c3e65c2b180c1625502ea"
108-
assert signature_mainnet["s"] == "0x718a068b27584ae85c330aa5da84bd5d6ac5f126ee2db67cc752f431c3d9b7e5"
109-
assert signature_mainnet["v"] == 28
107+
assert signature_mainnet["r"] == "0x41ae18e8239a56cacbc5dad94d45d0b747e5da11ad564077fcac71277a946e3"
108+
assert signature_mainnet["s"] == "0x3c61f667e747404fe7eea8f90ab0e76cc12ce60270438b2058324681a00116da"
109+
assert signature_mainnet["v"] == 27
110110

111111
signature_testnet = sign_l1_action(
112112
wallet,
@@ -115,8 +115,8 @@ def test_l1_action_signing_order_with_cloid_matches():
115115
timestamp,
116116
False,
117117
)
118-
assert signature_testnet["r"] == "0x6c9dd46e78f7eab4fc206a53dcc334c904820fedd1e023203ad12cd656953095"
119-
assert signature_testnet["s"] == "0x591e8dcb374c3317d14883bc4d65fd8ea2ae0556c9b1dd425220cf173dbc2d83"
118+
assert signature_testnet["r"] == "0xeba0664bed2676fc4e5a743bf89e5c7501aa6d870bdb9446e122c9466c5cd16d"
119+
assert signature_testnet["s"] == "0x7f3e74825c9114bc59086f1eebea2928c190fdfbfde144827cb02b85bbe90988"
120120
assert signature_testnet["v"] == 28
121121

122122

0 commit comments

Comments
 (0)