not working port to p3

main
Christoph Schneeberger 8 months ago
parent b625eca5bd
commit 8b717912a6

@ -32,7 +32,12 @@
####################### #######################
# IMPORTS # 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 # CONSTANTS
@ -52,7 +57,7 @@ def calc_totals(trades):
global quiet global quiet
for t in trades: for t in trades:
if not quiet: 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': if t['type'] == 'sell':
sum_s1 += float(t['vol']) sum_s1 += float(t['vol'])
sum_s2 += float(t['cost']) sum_s2 += float(t['cost'])
@ -69,10 +74,10 @@ def calc_totals(trades):
avg_b = 0 avg_b = 0
if not quiet: hrule("=") if not quiet: hrule("=")
print "*BUY*:\tAmount\t\tVolume\t\tAvg. price" print ("*BUY*:\tAmount\t\tVolume\t\tAvg. price")
print "\t%f\t%f\t%f" %(sum_b1, sum_b2, avg_b) print ("\t%f\t%f\t%f" %(sum_b1, sum_b2, avg_b))
print "*SELL*:\tAmount\t\tVolume\t\tAvg. price" print ("*SELL*:\tAmount\t\tVolume\t\tAvg. price")
print "\t%f\t%f\t%f" %(sum_s1, sum_s2, avg_s) print ("\t%f\t%f\t%f" %(sum_s1, sum_s2, avg_s) )
hrule("=") hrule("=")
return [sum_b1, sum_b2, avg_b, sum_s1, sum_s2, avg_s,] return [sum_b1, sum_b2, avg_b, sum_s1, sum_s2, avg_s,]
@ -83,7 +88,7 @@ def get_krakenticker(url):
def hrule(character): def hrule(character):
print character*linelen print (character*linelen)
def parse_param(argv): def parse_param(argv):
@ -97,7 +102,7 @@ def parse_param(argv):
def show_usage(): def show_usage():
print """ print ("""
Usage: Usage:
%s -f <csv-file> [-p <KRAKENPAIR>] [--help] [--quiet] [--short] %s -f <csv-file> [-p <KRAKENPAIR>] [--help] [--quiet] [--short]
@ -110,7 +115,7 @@ To save output in a file use shell redirect:
To print output, pipe it through lp: To print output, pipe it through lp:
%s -f <csv-file> | lp -d <printer-name> -o fit-to-page %s -f <csv-file> | lp -d <printer-name> -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) sys.exit(1)
@ -154,21 +159,21 @@ if __name__ == '__main__':
pairs = data.keys() pairs = data.keys()
for pair in pairs: for pair in pairs:
if pair_only and pair_only != pair: if pair_only and pair_only != pair:
print "Match, abort" print ("Match, abort")
continue continue
print print
price = float(krakenprice[pair]['c'][0].rstrip("0")) price = float(krakenprice[pair]['c'][0].rstrip("0"))
#print "Current Krakenprice [%s]: %0.6f" %(pair, price,) #print "Current Krakenprice [%s]: %0.6f" %(pair, price,)
hrule("-") hrule("-")
print " "*20 + pair + " [%0.6f]"%price + " "*20 print (" "*20 + pair + " [%0.6f]"%price + " "*20)
hrule("-") hrule("-")
result_data[pair] = calc_totals(data[pair]) result_data[pair] = calc_totals(data[pair])
profit_buy = ( result_data[pair][0] * price ) - (result_data[pair][0] * result_data[pair][2]) 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 ) profit_sell = (result_data[pair][3] * result_data[pair][5]) - ( result_data[pair][3] * price )
print "Profit [SELL] =", profit_sell print ("Profit [SELL] =", profit_sell)
print "Profit =", profit_buy + profit_sell print ("Profit =", profit_buy + profit_sell)
hrule("*") hrule("*")
# results_data is not used yet, maybe removed later # results_data is not used yet, maybe removed later

Loading…
Cancel
Save