Created
June 2, 2021 07:35
-
-
Save tzhenghao/45060b39bfcf2d01ffb3c9146fd5eb7e to your computer and use it in GitHub Desktop.
A Python script to query stake account balances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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