Skip to content

Commit

Permalink
Version 0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
traderben committed Feb 20, 2024
1 parent cf2024d commit c25ecb6
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 43 deletions.
11 changes: 2 additions & 9 deletions hyperliquid/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,11 @@ def funding_history(self, coin: str, startTime: int, endTime: Optional[int] = No

def user_funding_history(self, user: str, startTime: int, endTime: Optional[int] = None) -> Any:
"""Retrieve a user's funding history
POST /info
Args:
user (str): Address of the user in 42-character hexadecimal format.
startTime (int): Start time in milliseconds, inclusive.
endTime (int, optional): End time in milliseconds, inclusive. Defaults to current time.
Returns:
List[Dict]: A list of funding history records, where each record contains:
- user (str): User address.
Expand All @@ -214,12 +211,8 @@ def user_funding_history(self, user: str, startTime: int, endTime: Optional[int]
- endTime (int): Unix timestamp of the end time in milliseconds.
"""
if endTime is not None:
return self.post(
"/info", {"type": "userFunding", "user": user, "startTime": startTime, "endTime": endTime}
)
return self.post(
"/info", {"type": "userFunding", "user": user, "startTime": startTime}
)
return self.post("/info", {"type": "userFunding", "user": user, "startTime": startTime, "endTime": endTime})
return self.post("/info", {"type": "userFunding", "user": user, "startTime": startTime})

def l2_snapshot(self, coin: str) -> Any:
"""Retrieve L2 snapshot for a given coin
Expand Down
155 changes: 149 additions & 6 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "hyperliquid-python-sdk"
version = "0.2.0"
version = "0.2.1"
description = "SDK for Hyperliquid API trading with Python."
readme = "README.md"
authors = ["Hyperliquid <[email protected]>"]
Expand Down Expand Up @@ -43,7 +43,7 @@ eth-abi = "^3.0.1"
eth-account = "^0.8.0"
websocket-client = "^1.5.1"
requests = "^2.31.0"
msgpack-python = "^0.5.6"
msgpack = "^1.0.5"

[tool.poetry.dev-dependencies]
python = "3.10.10"
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ eth-typing==3.2.0 ; python_version >= "3.7" and python_version < "4"
eth-utils==2.2.0 ; python_version >= "3.7" and python_version < "4"
hexbytes==0.3.1 ; python_version >= "3.7" and python_version < "4"
idna==3.4 ; python_version >= "3.7" and python_version < "4.0"
msgpack-python==0.5.6 ; python_version >= "3.7" and python_version < "4.0"
msgpack==1.0.5 ; python_version >= "3.7" and python_version < "4.0"
parsimonious==0.8.1 ; python_version >= "3.7" and python_version < "4"
pycryptodome==3.18.0 ; python_version >= "3.7" and python_version < "4"
requests==2.31.0 ; python_version >= "3.7" and python_version < "4.0"
rlp==3.0.0 ; python_version >= "3.7" and python_version < "4"
six==1.16.0 ; python_version >= "3.7" and python_version < "4"
toolz==0.12.0 ; python_version >= "3.7" and python_version < "4" and (implementation_name == "pypy" or implementation_name == "cpython")
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"
urllib3==1.26.16 ; python_version >= "3.7" and python_version < "4.0"
websocket-client==1.6.1 ; python_version >= "3.7" and python_version < "4.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
interactions:
- request:
body: '{"type": "userFunding", "user": "0xb7b6f3cea3f66bf525f5d8f965f6dbf6d9b017b2",
"startTime": 1681923833000, "endTime": 1682010233000}'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '131'
Content-Type:
- application/json
User-Agent:
- python-requests/2.31.0
method: POST
uri: https://api.hyperliquid.xyz/info
response:
body:
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}]'
headers:
access-control-allow-origin:
- '*'
access-control-expose-headers:
- '*'
content-length:
- '2796'
content-type:
- application/json
date:
- Tue, 20 Feb 2024 17:42:28 GMT
vary:
- origin
- access-control-request-method
- access-control-request-headers
status:
code: 200
message: OK
version: 1

Large diffs are not rendered by default.

34 changes: 15 additions & 19 deletions tests/info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,33 +93,29 @@ def test_get_candles_snapshot():
def test_user_funding_history_with_end_time():
info = Info(skip_ws=True)
response = info.user_funding_history(
user="0xb7b6f3cea3f66bf525f5d8f965f6dbf6d9b017b2",
startTime=1681923833000,
endTime=1682010233000
user="0xb7b6f3cea3f66bf525f5d8f965f6dbf6d9b017b2", startTime=1681923833000, endTime=1682010233000
)
assert isinstance(response, list), "The answer should be a list"
for record in response:
assert 'delta' in record, "There must be a key 'delta'"
assert 'hash' in record, "There must be a key 'hash'"
assert 'time' in record, "There must be a key 'time'"
delta = record['delta']
for key in ['coin', 'fundingRate', 'szi', 'type', 'usdc']:
assert "delta" in record, "There must be a key 'delta'"
assert "hash" in record, "There must be a key 'hash'"
assert "time" in record, "There must be a key 'time'"
delta = record["delta"]
for key in ["coin", "fundingRate", "szi", "type", "usdc"]:
assert key in delta, f"В 'delta' There must be a key '{key}'"
assert delta['type'] == 'funding', "The type must be 'funding'"
assert delta["type"] == "funding", "The type must be 'funding'"


@pytest.mark.vcr()
def test_user_funding_history_without_end_time():
info = Info(skip_ws=True)
response = info.user_funding_history(
user="0xb7b6f3cea3f66bf525f5d8f965f6dbf6d9b017b2",
startTime=1681923833000
)
response = info.user_funding_history(user="0xb7b6f3cea3f66bf525f5d8f965f6dbf6d9b017b2", startTime=1681923833000)
assert isinstance(response, list), "The answer must be a list"
for record in response:
assert 'delta' in record, "There must be a key 'delta'"
assert 'hash' in record, "There must be a key 'hash'"
assert 'time' in record, "There must be a key 'time'"
delta = record['delta']
for key in ['coin', 'fundingRate', 'szi', 'type', 'usdc']:
assert "delta" in record, "There must be a key 'delta'"
assert "hash" in record, "There must be a key 'hash'"
assert "time" in record, "There must be a key 'time'"
delta = record["delta"]
for key in ["coin", "fundingRate", "szi", "type", "usdc"]:
assert key in delta, f"В 'delta' There must be a '{key}'"
assert delta['type'] == 'funding', "The type must be 'funding'"
assert delta["type"] == "funding", "The type must be 'funding'"
10 changes: 5 additions & 5 deletions tests/signing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def test_l1_action_signing_order_with_cloid_matches():
timestamp,
True,
)
assert signature_mainnet["r"] == "0xb3bb4fb9ccc13c11ff5e0e387bbf181c6542a0b62a5c3e65c2b180c1625502ea"
assert signature_mainnet["s"] == "0x718a068b27584ae85c330aa5da84bd5d6ac5f126ee2db67cc752f431c3d9b7e5"
assert signature_mainnet["v"] == 28
assert signature_mainnet["r"] == "0x41ae18e8239a56cacbc5dad94d45d0b747e5da11ad564077fcac71277a946e3"
assert signature_mainnet["s"] == "0x3c61f667e747404fe7eea8f90ab0e76cc12ce60270438b2058324681a00116da"
assert signature_mainnet["v"] == 27

signature_testnet = sign_l1_action(
wallet,
Expand All @@ -115,8 +115,8 @@ def test_l1_action_signing_order_with_cloid_matches():
timestamp,
False,
)
assert signature_testnet["r"] == "0x6c9dd46e78f7eab4fc206a53dcc334c904820fedd1e023203ad12cd656953095"
assert signature_testnet["s"] == "0x591e8dcb374c3317d14883bc4d65fd8ea2ae0556c9b1dd425220cf173dbc2d83"
assert signature_testnet["r"] == "0xeba0664bed2676fc4e5a743bf89e5c7501aa6d870bdb9446e122c9466c5cd16d"
assert signature_testnet["s"] == "0x7f3e74825c9114bc59086f1eebea2928c190fdfbfde144827cb02b85bbe90988"
assert signature_testnet["v"] == 28


Expand Down

0 comments on commit c25ecb6

Please sign in to comment.