Skip to content

Commit

Permalink
Correct current balance query
Browse files Browse the repository at this point in the history
  • Loading branch information
rzippert committed Oct 23, 2021
1 parent 64c90c4 commit 6564363
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions richwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
spotsum = client.account_snapshot("SPOT")

# print report
print ("Richwatch 0.1")
# spotsum is a json with snapshots of crypto values, so we get the last entry (-1) and translate the date to print
print (" Data from: %s" % (datetime.datetime.fromtimestamp(int(spotsum["snapshotVos"][-1]['updateTime'])/1000)))
print ("Richwatch 0.2")
assetsum = 0.0

# once the last snapshot is selected, crypto with 0 value is ignored, while crypto I have is accounted
for balance in spotsum["snapshotVos"][-1]['data']['balances']:
if float(balance["free"]) != 0:
assetqty = float(balance["free"])
for balance in client.account()["balances"]:
if float(balance["free"]) != 0 or float(balance["locked"]) != 0:
assetqty = float(balance["free"]) + float(balance["locked"])
if balance["asset"] != "USDT":
# if the crypto is not called USDT, it must be multiplied by its value in USDT
assetvalue = float(client.avg_price(balance["asset"] + "USDT")["price"])
Expand All @@ -36,3 +33,25 @@
brlvalue = float(client.avg_price("USDTBRL")["price"])
# total is also measured in BRL for additional commodity
print("Total: US$ %.2f / R$ %.2f" % (assetsum, assetsum * brlvalue))

# spotsum is a json with snapshots of crypto values, so we get the last entry (-1) and translate the date to print
#print (" Data from: %s" % (datetime.datetime.fromtimestamp(int(spotsum["snapshotVos"][-1]['updateTime'])/1000)))
#assetsum = 0.0
#
## once the last snapshot is selected, crypto with 0 value is ignored, while crypto I have is accounted
#for balance in spotsum["snapshotVos"][-1]['data']['balances']:
# if float(balance["free"]) != 0:
# assetqty = float(balance["free"])
# if balance["asset"] != "USDT":
# # if the crypto is not called USDT, it must be multiplied by its value in USDT
# assetvalue = float(client.avg_price(balance["asset"] + "USDT")["price"])
# else:
# # if the crypto is called USDT, it must be multiplied by 1
# assetvalue = 1.0
# usvalue = assetvalue * assetqty
# assetsum += usvalue
# print(" %s: US$ %.2f = %.2f @ US$ %.2f" % (balance["asset"], usvalue, assetqty, assetvalue ))
#brlvalue = float(client.avg_price("USDTBRL")["price"])
## total is also measured in BRL for additional commodity
#print("Total: US$ %.2f / R$ %.2f" % (assetsum, assetsum * brlvalue))
#

0 comments on commit 6564363

Please sign in to comment.