Skip to content

Commit 3e1f97d

Browse files
authored
Addition of Staking Info (#92)
1 parent 24f33ea commit 3e1f97d

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

examples/basic_staking.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import json
2+
3+
import example_utils
4+
5+
from hyperliquid.utils import constants
6+
7+
8+
def main():
9+
address, info, exchange = example_utils.setup(base_url=constants.MAINNET_API_URL, skip_ws=True)
10+
11+
# Get the user staking summary and print information
12+
user_staking_summary = info.user_staking_summary(address)
13+
print("Staking summary:")
14+
print(json.dumps(user_staking_summary, indent=2))
15+
16+
# Get the user staking delegations and print information
17+
user_stakes = info.user_stakes(address)
18+
print("Staking breakdown:")
19+
print(json.dumps(user_stakes, indent=2))
20+
21+
# Get the user staking reward history and print information
22+
user_staking_rewards= info.user_staking_rewards(address)
23+
print("Most recent staking rewards:")
24+
print(json.dumps(user_staking_rewards[:5], indent=2))
25+
26+
if __name__ == "__main__":
27+
main()

hyperliquid/info.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,56 @@ def user_fees(self, address: str) -> Any:
500500
}
501501
"""
502502
return self.post("/info", {"type": "userFees", "user": address})
503+
504+
def user_staking_summary(self, address: str) -> Any:
505+
"""Retrieve the staking summary associated with a user.
506+
POST /info
507+
Args:
508+
address (str): Onchain address in 42-character hexadecimal format;
509+
e.g. 0x0000000000000000000000000000000000000000.
510+
Returns:
511+
{
512+
delegated: float string,
513+
undelegated: float string,
514+
totalPendingWithdrawal: float string,
515+
nPendingWithdrawals: int
516+
}
517+
"""
518+
return self.post("/info", {"type": "delegatorSummary", "user": address})
519+
520+
def user_staking_delegations(self, address: str) -> Any:
521+
"""Retrieve the user's staking delegations.
522+
POST /info
523+
Args:
524+
address (str): Onchain address in 42-character hexadecimal format;
525+
e.g. 0x0000000000000000000000000000000000000000.
526+
Returns:
527+
[
528+
{
529+
validator: string,
530+
amount: float string,
531+
lockedUntilTimestamp: int
532+
},
533+
]
534+
"""
535+
return self.post("/info", {"type": "delegations", "user": address})
536+
537+
def user_staking_rewards(self, address: str) -> Any:
538+
"""Retrieve the historic staking rewards associated with a user.
539+
POST /info
540+
Args:
541+
address (str): Onchain address in 42-character hexadecimal format;
542+
e.g. 0x0000000000000000000000000000000000000000.
543+
Returns:
544+
[
545+
{
546+
time: int,
547+
source: string,
548+
totalAmount: float string
549+
},
550+
]
551+
"""
552+
return self.post("/info", {"type": "delegatorRewards", "user": address})
503553

504554
def query_order_by_oid(self, user: str, oid: int) -> Any:
505555
return self.post("/info", {"type": "orderStatus", "user": user, "oid": oid})

0 commit comments

Comments
 (0)