· 4 years ago · Feb 13, 2021, 09:14 PM
1#!/usr/bin/python3
2#Config
3investimentoinicial = 65 + 35 + 35 + 50 #reais q colocou na exchange
4apikey = ''
5secretkey = ''
6#end
7
8#region Imports e Variaveis
9import json
10import requests
11try:
12 from novadax import RequestClient as NovaClient
13 nova_client = NovaClient(apikey, secretkey)
14except ImportError as e:
15 print("Necessario instalar o pacote novadax \nExecutar: pip3 install novadax")
16 exit()
17
18#region Variaveis
19bal = ""
20cart = ""
21valormoeda = ""
22totalmoedas = float(0)
23currency = []
24prices = []
25#endregion
26#endregion
27
28#region NovaDax
29Coins = json.loads(json.dumps(nova_client.get_account_balance_current()["data"]["assets"])) #Recebe o JSON das moedas na conta
30def getPrice(coin): #Retorna valor da moeda especificada
31 return float(json.dumps(nova_client.get_ticker(coin + "_BRL")["data"]["lastPrice"]).replace('"', ''))
32
33for key in Coins: #Define os valores para cada moeda na lista
34 currency.append(key['currency']) #adiciona a moeda atual na lista 'currency'
35 try: #Acessar API de valor com getPrice e adicionar o valor á lista 'prices' na mesma posição da moeda
36 prices.append(getPrice(str(key['currency']))) #Adiciona o valor da moeda a segunda lista
37 except:
38 prices.append(0) #Caso API não retorne um valor, adicionar 0 no local (BRL/USDT)
39 totalmoedas = totalmoedas + (float(key['balance']) * prices[currency.index(key['currency'])]) #Somar a moeda atual ao total
40 if float(key['balance']) > 0 and key['currency'] != "BRL": #Gera a lista de moedas do Tooltip (ignorando BRL)
41 cart = cart + "\n - " + key['currency'] + ": " + str(format((float(key['balance']) * prices[currency.index(key['currency'])]), '.2f')) + "R$" #Valor atual em reais das moedas
42 valormoeda = valormoeda + "\n - " + key['currency'] + ": " + str(format(prices[currency.index(key['currency'])], '.2f')) + "R$" #Lista de cotações atuais das moedas
43 bal = bal + "\n - " + key['currency'] + ": " + key['balance'] #Balança das moedas na conta
44 if key['currency'] == "BRL": #Reais na conta
45 BRL = float(key['balance'])
46#endregion
47
48#region Output
49out = {
50 "text": " : " + str(format(totalmoedas, '.2f')) +
51 "R$ | BRL: " + str(BRL) +
52 "R$ | Total: " + str(format(totalmoedas + BRL, '.2f')) +
53 "R$ | DOT: " + str(format(prices[currency.index("DOT")], '.2f')) +
54 "R$ | LINK: " + str(format(prices[currency.index("LINK")], '.2f')) + "R$",
55
56 "tooltip" : "Investimento: " + str(investimentoinicial) + "R$" +
57 "\n\nCarteira: " + str(format(totalmoedas + BRL, '.2f')) + "R$" + cart +
58 "\n\nValor Atual:" + valormoeda +
59 "\n\nMoedas:" + bal
60}
61print(json.dumps(out))
62#endregion