Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- #Config
- investimentoinicial = 65 + 35 + 35 + 50 #reais q colocou na exchange
- apikey = ''
- secretkey = ''
- #end
- #region Imports e Variaveis
- import json
- import requests
- try:
- from novadax import RequestClient as NovaClient
- nova_client = NovaClient(apikey, secretkey)
- except ImportError as e:
- print("Necessario instalar o pacote novadax \nExecutar: pip3 install novadax")
- exit()
- #region Variaveis
- bal = ""
- cart = ""
- valormoeda = ""
- totalmoedas = float(0)
- currency = []
- prices = []
- #endregion
- #endregion
- #region NovaDax
- Coins = json.loads(json.dumps(nova_client.get_account_balance_current()["data"]["assets"])) #Recebe o JSON das moedas na conta
- def getPrice(coin): #Retorna valor da moeda especificada
- return float(json.dumps(nova_client.get_ticker(coin + "_BRL")["data"]["lastPrice"]).replace('"', ''))
- for key in Coins: #Define os valores para cada moeda na lista
- currency.append(key['currency']) #adiciona a moeda atual na lista 'currency'
- try: #Acessar API de valor com getPrice e adicionar o valor á lista 'prices' na mesma posição da moeda
- prices.append(getPrice(str(key['currency']))) #Adiciona o valor da moeda a segunda lista
- except:
- prices.append(0) #Caso API não retorne um valor, adicionar 0 no local (BRL/USDT)
- totalmoedas = totalmoedas + (float(key['balance']) * prices[currency.index(key['currency'])]) #Somar a moeda atual ao total
- if float(key['balance']) > 0 and key['currency'] != "BRL": #Gera a lista de moedas do Tooltip (ignorando BRL)
- cart = cart + "\n - " + key['currency'] + ": " + str(format((float(key['balance']) * prices[currency.index(key['currency'])]), '.2f')) + "R$" #Valor atual em reais das moedas
- valormoeda = valormoeda + "\n - " + key['currency'] + ": " + str(format(prices[currency.index(key['currency'])], '.2f')) + "R$" #Lista de cotações atuais das moedas
- bal = bal + "\n - " + key['currency'] + ": " + key['balance'] #Balança das moedas na conta
- if key['currency'] == "BRL": #Reais na conta
- BRL = float(key['balance'])
- #endregion
- #region Output
- out = {
- "text": " : " + str(format(totalmoedas, '.2f')) +
- "R$ | BRL: " + str(BRL) +
- "R$ | Total: " + str(format(totalmoedas + BRL, '.2f')) +
- "R$ | DOT: " + str(format(prices[currency.index("DOT")], '.2f')) +
- "R$ | LINK: " + str(format(prices[currency.index("LINK")], '.2f')) + "R$",
- "tooltip" : "Investimento: " + str(investimentoinicial) + "R$" +
- "\n\nCarteira: " + str(format(totalmoedas + BRL, '.2f')) + "R$" + cart +
- "\n\nValor Atual:" + valormoeda +
- "\n\nMoedas:" + bal
- }
- print(json.dumps(out))
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement