Files
ProfitLib/balances.py
2015-07-08 09:52:19 -07:00

75 lines
2.6 KiB
Python
Executable File

#!/usr/bin/env python
# coding=iso-8859-1
# balances.py: get wallet balances and find best bid on all exchanges
#
# Copyright © 2015 Scott Alfter
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import jsonrpc
import json
from ProfitLib import *
daemons=json.loads(open("daemon_config.json").read())
exchanges=json.loads(open("exchange_config.json").read())
pl=ProfitLib(daemons, exchanges)
pl.GetMarketIDs()
balances={}
btcbal=Decimal(0)
for i, coin in enumerate(daemons):
if (daemons[coin]["active"]==1):
url="http://"+daemons[coin]["username"]+":"+daemons[coin]["passwd"]+"@"+daemons[coin]["host"]+":"+str(daemons[coin]["port"])
b=jsonrpc.ServiceProxy(url)
try:
bal=b.getbalance()
if (bal>0):
bid=pl.GetBestBid(coin.split("_")[0])
if (coin!="BTC"):
balances[coin.split("_")[0]]=[str(bal), str((bid[0]*Decimal(bal)).quantize(Decimal("1.00000000"))), bid[1]]
btcbal+=bid[0]*Decimal(bal)
else:
balances[coin.split("_")[0]]=[str(bal), str(bal), ""]
btcbal+=Decimal(bal)
except IOError:
print coin+" offline"
exchtotals={}
for i, coin in enumerate(balances):
try:
exchtotals[balances[coin][2]]+=Decimal(balances[coin][1])
except:
exchtotals[balances[coin][2]]=Decimal(balances[coin][1])
for i, coin in enumerate(balances):
if (coin=="BTC"):
print coin+": "+balances[coin][0]
else:
print coin+": "+balances[coin][0]+" ("+balances[coin][1]+" BTC @ "+balances[coin][2]+")"
print
for i, exch in enumerate(exchtotals):
if (exch!=""):
print exch+": "+str(exchtotals[exch])+" BTC"
print
print "BTC total: "+str(btcbal.quantize(Decimal("1.00000000")))