diff --git a/kraken-report.py b/kraken-report.py index b3838dd..9695d0a 100755 --- a/kraken-report.py +++ b/kraken-report.py @@ -32,7 +32,12 @@ ####################### # IMPORTS ####################### -import csv, sys, getopt, requests +import csv, sys, getopt +try: + import requests +except: + print ("python-requests library missing, install with:\nsudo apt-get install python3-requests") + sys.exit(1) ####################### # CONSTANTS @@ -52,7 +57,7 @@ def calc_totals(trades): global quiet for t in trades: if not quiet: - print "%s %s %s %0.4f %f %0.2f" %(t['time'].split(".")[0], t['pair'], t['type'], float(t['price']), float(t['vol']), float(t['cost'])) + print ("%s %s %s %0.4f %f %0.2f" %(t['time'].split(".")[0], t['pair'], t['type'], float(t['price']), float(t['vol']), float(t['cost'])) ) if t['type'] == 'sell': sum_s1 += float(t['vol']) sum_s2 += float(t['cost']) @@ -69,10 +74,10 @@ def calc_totals(trades): avg_b = 0 if not quiet: hrule("=") - print "*BUY*:\tAmount\t\tVolume\t\tAvg. price" - print "\t%f\t%f\t%f" %(sum_b1, sum_b2, avg_b) - print "*SELL*:\tAmount\t\tVolume\t\tAvg. price" - print "\t%f\t%f\t%f" %(sum_s1, sum_s2, avg_s) + print ("*BUY*:\tAmount\t\tVolume\t\tAvg. price") + print ("\t%f\t%f\t%f" %(sum_b1, sum_b2, avg_b)) + print ("*SELL*:\tAmount\t\tVolume\t\tAvg. price") + print ("\t%f\t%f\t%f" %(sum_s1, sum_s2, avg_s) ) hrule("=") return [sum_b1, sum_b2, avg_b, sum_s1, sum_s2, avg_s,] @@ -83,7 +88,7 @@ def get_krakenticker(url): def hrule(character): - print character*linelen + print (character*linelen) def parse_param(argv): @@ -97,7 +102,7 @@ def parse_param(argv): def show_usage(): - print """ + print (""" Usage: %s -f [-p ] [--help] [--quiet] [--short] @@ -110,7 +115,7 @@ To save output in a file use shell redirect: To print output, pipe it through lp: %s -f | lp -d -o fit-to-page -""" %(sys.argv[0], sys.argv[0], sys.argv[0], sys.argv[0]) +""" %(sys.argv[0], sys.argv[0], sys.argv[0], sys.argv[0]) ) sys.exit(1) @@ -154,21 +159,21 @@ if __name__ == '__main__': pairs = data.keys() for pair in pairs: if pair_only and pair_only != pair: - print "Match, abort" + print ("Match, abort") continue print price = float(krakenprice[pair]['c'][0].rstrip("0")) #print "Current Krakenprice [%s]: %0.6f" %(pair, price,) hrule("-") - print " "*20 + pair + " [%0.6f]"%price + " "*20 + print (" "*20 + pair + " [%0.6f]"%price + " "*20) hrule("-") result_data[pair] = calc_totals(data[pair]) profit_buy = ( result_data[pair][0] * price ) - (result_data[pair][0] * result_data[pair][2]) - print "Profit [BUY] =", profit_buy + print ("Profit [BUY] =", profit_buy) profit_sell = (result_data[pair][3] * result_data[pair][5]) - ( result_data[pair][3] * price ) - print "Profit [SELL] =", profit_sell - print "Profit =", profit_buy + profit_sell + print ("Profit [SELL] =", profit_sell) + print ("Profit =", profit_buy + profit_sell) hrule("*") # results_data is not used yet, maybe removed later