Advertisement
atorresbr

Carteira NOVADax

Feb 14th, 2021
575
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python3
  2. #Config
  3. investimentoinicial = 65 + 35 + 35 + 50 #reais q colocou na exchange
  4. apikey = ''
  5. secretkey = ''
  6. #end
  7.  
  8. #region Imports e Variaveis
  9. import json
  10. import requests
  11. try:
  12.     from novadax import RequestClient as NovaClient
  13.     nova_client = NovaClient(apikey, secretkey)
  14. except ImportError as e:
  15.     print("Necessario instalar o pacote novadax \nExecutar: pip3 install novadax")
  16.     exit()
  17.  
  18. #region Variaveis
  19. bal = ""
  20. cart = ""
  21. valormoeda = ""
  22. totalmoedas = float(0)
  23. currency = []
  24. prices = []
  25. #endregion
  26. #endregion
  27.  
  28. #region NovaDax
  29. Coins = json.loads(json.dumps(nova_client.get_account_balance_current()["data"]["assets"])) #Recebe o JSON das moedas na conta
  30. def getPrice(coin): #Retorna valor da moeda especificada
  31.     return float(json.dumps(nova_client.get_ticker(coin + "_BRL")["data"]["lastPrice"]).replace('"', ''))
  32.  
  33. for 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
  49. out = {
  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. }
  61. print(json.dumps(out))
  62. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement