Python script keeps track of wallets in multiple cryptocurrencies

If you have coins scattered around multiple addresses in various crytpocurrencies, it's a pain to keep track of your balances. I know there are good apps for that on Android, but I don't have an Android phone and I was not satisfied with what was available elsewhere, so I made a simple Python script that uses APIs to keep track of multiple addresses in multiple cryptocurrencies and converts the values to my home fiat currency. It also calculates my profit based on my buy history. It's a very basic script, but it does just what I want, and it will work on any machine that has Python3 installed and the 'requests' module. Might be useful to you too, so here it is:

# Use this script to keep track of your multiple crypto wallets. # It checks the balance of multiple public addresses and displays # the sum per currency. It also converts all your coins to your # preferred fiat currency. If you give it the history of all the # amounts in fiat currency that you spent to buy coins, it will # calculate your total profits/losses. # If you find this script useful, tips are appreciated: # Bitcoin 1Nae2EQdUZf4z9w2tz7hzQuHqngCoiY2CG # Ethereum 0xe691dDcaA35E62322e6141f902A64c4338A884c8 # Litecoin LbvUCHPTEJwmy4Nem6mmdD88SeesFJgVPp # Iota OXKJXJ9RTBAMHBMCHFYLVLXHGKFEGWONIXJOLBILIK9DREOYCQTYIXOZUTFRRH9AIYFWRUYJGAUWHQUG9UWITPMHQM # You need to install the requests module (pip3 install requests) import requests # List of amounts spent (in home currency) to buy coins # Change these numbers to reflect your own buy history. book = sum([ 403.99, 51.99, 25.00, 120.00 ]) # Table of addresses # Here you enter your public addresses. # First column is just a tag for you to remember which address is which. # Second column is the three-letter code for the crypto-currency. # Third column is the public address. **NOT YOUR PRIVATE KEY/SEED** # Of course you must change these address to put your own. # If you have several addresses for the same currency, just add more lines. # Don't forget the quotes! addresses = [ ('savings', 'btc', '1Nae2EQdUZf4z9w2tz7hzQuHqngCoiY2CG'), ('projects', 'eth', '0xe691dDcaA35E62322e6141f902A64c4338A884c8'), ('speculation', 'ltc', 'LbvUCHPTEJwmy4Nem6mmdD88SeesFJgVPp') ] # Preferred fiat currency symbol # Change this to your home currency fiat = 'usd' # Here is the list of the currencies you want to handle # Main keys are currency symbols # 'name' is the full name of the currency (not currently used by this script) # 'divisor' is used to convert the reported balance to the actual unit. # For example, bitcoin balances are reported in satoshis, and have to be # divided by 100,000,000 (10**8) to get the bitcoin value. # You can add currencies here if you like. currencies = { 'btc' : {'name':'bitcoin', 'divisor': 10**8 }, 'ltc' : {'name':'litecoin', 'divisor': 10**8 }, 'eth' : {'name':'ethereum', 'divisor': 10**18 }, 'iot' : {'name':'iota', 'divisor': 10**0 } } # You don't need to modify the rest of the script. for currency in currencies.keys(): url = 'http://ift.tt/2xxy3Vr currencies[currency]['rate'] = float(requests.get(url=url).json()[0]['price_'+fiat.lower()]) portfolio = {} for address in addresses: currency = address[1] if currency not in portfolio.keys(): portfolio[currency] = 0 addr = address[2] url = 'http://ift.tt/2wCHnLk; portfolio[currency] += round(requests.get(url=url).json()['final_balance'] / currencies[currency]['divisor'], 8) total = 0 for currency in portfolio.keys(): value = round(portfolio[currency]*currencies[currency]['rate'], 2) total += value print(portfolio[currency], currency.upper(), '=', value, fiat.upper()) print('Total current value', round(total, 2), fiat.upper()) print('Total book value', book, fiat.upper()) print('Total P/L', round(total-book, 2), fiat.upper()) 
submitted by /u/pacolaro
[link] [comments]

Read More

Popular posts from this blog

World Economic Forum Bitcoin Discussions Validate the Movement