Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Python script to query stake account balances
"""A Python script to query stake account balances"""
import json
import requests
import subprocess
STAKE_ACCOUNT_ADDRESSES = [
"<ADD_ALL_ADDRESSES_HERE>"
]
def query_current_price():
json_response = requests.get("https://ftx.com/api/markets/SOL/USD").json()
price = json_response["result"]["price"]
return price
def query_stake_account_balances():
total_amount = 0
print("Querying balance(s) of {} accounts".format(len(STAKE_ACCOUNT_ADDRESSES)))
for account in STAKE_ACCOUNT_ADDRESSES:
result = subprocess.run(
[
"solana",
"balance",
account,
],
capture_output=True,
)
amount = result.stdout.decode("utf-8").split(" ")[0]
print("Account {} has {} SOL".format(account, amount))
total_amount += float(amount)
return total_amount
def main():
total_amount_staked = query_stake_account_balances()
print("Total staked: {} SOL".format(total_amount_staked))
curr_price = query_current_price()
print("Current SOL price: ${}".format(curr_price))
print("Mark-to-market value: ${}".format(curr_price * total_amount_staked))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment