Monitor assets owned from python



  • I wanted to find out about total owned assets and their total value. So I wrote a python code to get the asset data. No need to enter pass phrase just the numeric account id. The highest bid value quantity is not considered in this code. Need to improve on that in future.

    import time
    import socket
    import urllib
    import urllib2
    import json
    import urllib
    import urllib2
    
    def connect(url,values):
            data = urllib.urlencode(values)
            req = urllib2.Request(url, data)
            try:
                    response = urllib2.urlopen(req)
                    the_page = response.read()
                    final_data = json.loads(the_page)
                    return final_data
            except:
                    return 0
    
    account_id=input("Account Id:")
    print("Connecting...")
    url = 'http://localhost:8125/burst'
    values = {'requestType' : 'getAccount',
              'account' : account_id}
    
    data = connect(url,values)
    if(data==0):
    	print("Net error!")
    	time.sleep(1)
    else:	
    	total_asset_value=0
    	for asset in data['assetBalances']:
    		print("")
    	
    		values={'requestType' :'getAsset','asset':asset['asset']}
    		data_asset= connect(url,values)
    		if(data_asset==0):
    			print("Net error!")
    			time.sleep(1)
    		
    		values={'requestType':'getBidOrders','asset':asset['asset'],'lastIndex':'0'}
    		data_bid = connect(url,values)
    		if(data_bid==0):
    			print("Net error!")
    			time.sleep(1)
    		
    	
    		print("asset ID:"+asset['asset'])
    		print("asset name:"+data_asset['name'])
    		asset_bal=float(asset['balanceQNT'])/(10**data_asset['decimals'])
    		print("Qty:"+str(asset_bal))
    	#print("decimals:"+str(data_asset['decimals']))
    	
    		try:
    			
    			bid_value=float(data_bid['bidOrders'][0]['priceNQT'])/10**(8-int(data_asset['decimals']))
    		
    			print("Highest Bid:"+str(bid_value))
    		
    			asset_value_burst=bid_value * float(asset_bal)
    			print("Value in Burst:"+str(asset_value_burst))
    			total_asset_value=total_asset_value+float(asset_value_burst)
    	
    	
    	        except :
    			print("Highest Bid: None")
    	
    
    #balance=float(data['guaranteedBalanceNQT'])/100000000
    	balance=float(data['unconfirmedBalanceNQT'])/100000000
    
    	print("=============================")
    	print("Wallet Balance:"+"{0:.2f}".format(balance))
    	print("Total Asset Value:"+str(total_asset_value))
    	print("=============================")
    	values = {'requestType' : 'getBlockchainStatus'}
    
    data = connect(url,values)
    print("Height:"+str(data['lastBlockchainFeederHeight']))
    
    


  • Output for the above code.

    Account Id:17132087616482062663
    Connecting...
    
    asset ID:6037211370250490240
    asset name:hsassets
    Qty:100.0
    Highest Bid:88.0
    Value in Burst:8800.0
    
    asset ID:1892701762360056549
    asset name:btcdragon
    Qty:10.0
    Highest Bid:90.0
    Value in Burst:900.0
    
    asset ID:16885738494266455518
    asset name:SolarGrid
    Qty:110.0
    Highest Bid: None
    
    asset ID:15266167261394017138
    asset name:casino
    Qty:25.0
    Highest Bid:370.0
    Value in Burst:9250.0
    
    asset ID:2264511436216725766
    asset name:Lex4All
    Qty:10.0
    Highest Bid:12.0
    Value in Burst:120.0
    =============================
    Wallet Balance:11.99
    Total Asset Value:19070.0
    =============================
    Height:334963
    
    


  • If there is a bug in the code please let me know.



  • @sleepy Great!!



  • Assume you want to check all the amount in the wallet and assets in multiple account,
    Simple python code to check the grand total. Assuming a local wallet is running.
    The addresses of all the burst addresses can be in the BurstAddresses file.

    Main code , info.py

    import time
    import socket
    import urllib
    import urllib2
    import json
    import urllib
    import urllib2
    
    def connect(url,values):
            data = urllib.urlencode(values)
            req = urllib2.Request(url, data)
            try:
                    response = urllib2.urlopen(req)
                    the_page = response.read()
                    final_data = json.loads(the_page)
                    return final_data
            except:
                    return 0
    file = open("BurstAddresses", "r") 
    addresses = file.readlines() 
    
    #account_id=input("Account Id:")
    
    grand_total_asset_value=0
    grand_wallet_value=0
    for account_id in addresses:
    	print account_id
    	
    	print("Connecting...")
    	url = 'http://127.0.0.1:8125/burst'
    	values = {'requestType' : 'getAccount',
    	          'account' : account_id}
    	
    	data = connect(url,values)
    	if(data==0):
    		print("Net error!")
    		time.sleep(1)
    	else:	
    		total_asset_value=0
    		for asset in data['assetBalances']:
    			print("")
    		
    			values={'requestType' :'getAsset','asset':asset['asset']}
    			data_asset= connect(url,values)
    			if(data_asset==0):
    				print("Net error!")
    				time.sleep(1)
    			
    			values={'requestType':'getBidOrders','asset':asset['asset'],'lastIndex':'0'}
    			data_bid = connect(url,values)
    			if(data_bid==0):
    				print("Net error!")
    				time.sleep(1)
    			
    		
    			print("asset ID:"+asset['asset'])
    			print("asset name:"+data_asset['name'])
    			asset_bal=float(asset['balanceQNT'])/(10**data_asset['decimals'])
    			print("Qty:"+str(asset_bal))
    		#print("decimals:"+str(data_asset['decimals']))
    		
    			try:
    				
    				bid_value=float(data_bid['bidOrders'][0]['priceNQT'])/10**(8-int(data_asset['decimals']))
    			
    				print("Highest Bid:"+str(bid_value))
    			
    				asset_value_burst=bid_value * float(asset_bal)
    				print("Value in Burst:"+str(asset_value_burst))
    				total_asset_value=total_asset_value+float(asset_value_burst)
    		
    		
    		        except :
    				print("Highest Bid: None")
    		
    	
    	#balance=float(data['guaranteedBalanceNQT'])/100000000
    		balance=float(data['unconfirmedBalanceNQT'])/100000000
    	
    		print("=============================")
    		print("Wallet Balance:"+"{0:.2f}".format(balance))
    		print("Total Asset Value:"+str(total_asset_value))
    		print("=============================")
    		values = {'requestType' : 'getBlockchainStatus'}
    	
    	data = connect(url,values)
    	print("Height:"+str(data['lastBlockchainFeederHeight']))
    	
    	grand_total_asset_value=grand_total_asset_value+total_asset_value
    	grand_wallet_value=grand_wallet_value+balance
    	print("=============GRAND TOTAL============")
    	print("Wallet Balance:"+"{0:.2f}".format(grand_wallet_value))
    	print("Total Asset Value:"+str(grand_total_asset_value))
    	print("=============================")
    	print("Net Value:"+str(grand_total_asset_value+grand_wallet_value))
    	print("=============================")
    
    

    BurstAddresses file

    17132087616482062663
    10526241997328042230
    

    Output

    17132087616482062663
    
    Connecting...
    
    asset ID:6037211370250490240
    asset name:hsassets
    Qty:51.0
    Highest Bid:86.0
    Value in Burst:4386.0
    =============================
    Wallet Balance:218.18
    Total Asset Value:4386.0
    =============================
    Height:340991
    =============GRAND TOTAL============
    Wallet Balance:218.18
    Total Asset Value:4386.0
    =============================
    Net Value:4604.17629936
    =============================
    10526241997328042230
    Connecting...
    
    asset ID:6037211370250490240
    asset name:hsassets
    Qty:100.0
    Highest Bid:86.0
    Value in Burst:8600.0
    
    asset ID:16885738494266455518
    asset name:SolarGrid
    Qty:10000.0
    Highest Bid: None
    
    asset ID:1892701762360056549
    asset name:btcdragon
    Qty:20.0
    Highest Bid:70.0001
    Value in Burst:1400.002
    
    asset ID:15266167261394017138
    asset name:casino
    Qty:20.0
    Highest Bid:473.5
    Value in Burst:9470.0
    =============================
    Wallet Balance:2164.33
    Total Asset Value:19470.002
    =============================
    Height:340991
    =============GRAND TOTAL============
    Wallet Balance:2382.51
    Total Asset Value:23856.002
    =============================
    Net Value:26238.5088186
    =============================
    
    

Log in to reply
 

Looks like your connection to Burst - Efficient HDD Mining was lost, please wait while we try to reconnect.