-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.py
39 lines (27 loc) · 975 Bytes
/
account.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import config
from binance.client import Client
import json
from prettytable import PrettyTable
import pprint
import requests
client = Client(config.API_KEY, config.API_SECRET)
info = client.get_account()
t = PrettyTable(['ASSET', 'AMOUNT', 'PRICE', 'VALUE'])
balances = info['balances']
totalBalance = 0
for balance in balances:
amt = float(balance['free'])
if amt > 0:
avgPrice = client.get_avg_price(
symbol='{}BUSD'.format(balance['asset']))
value = float(balance['free']) * float(avgPrice['price'])
totalBalance += value
t.add_row([balance['asset'], balance['free'], avgPrice['price'], value])
r = requests.get(
'https://www.bankofcanada.ca/valet/observations/FXUSDCAD/json')
data = r.json()
rate = data['observations'][len(data['observations']) - 1]['FXUSDCAD']['v']
t.add_row(['', '', '', ''])
t.add_row(['', '', 'BUSD', totalBalance])
t.add_row(['', '', 'CAD', totalBalance * float(rate)])
print(t)