improved, cleaned up, bugfix

main
psycodad 2 years ago
parent 8fd4382ccb
commit d37091d762

@ -37,7 +37,6 @@ import csv, sys, getopt, requests
#######################
# CONSTANTS
#######################
price_pair = "XXBTZEUR"
linelen = 60
KRK_TICKER_URL = "https://api.kraken.com/0/public/Ticker"
@ -90,7 +89,7 @@ def hrule(character):
def parse_param(argv):
"""read cmd line params and switches"""
try:
opts, args = getopt.getopt(argv, "p:f:hqs", ["price=", "file=", "help", "quiet", "short", ])
opts, args = getopt.getopt(argv, "p:f:hqs", ["pair=", "file=", "help", "quiet", "short", ])
return opts, args
except getopt.GetoptError:
show_usage()
@ -100,8 +99,18 @@ def parse_param(argv):
def show_usage():
print """
Usage:
%s -f <csv-file> [--help] [--quiet] [--short]
""" %sys.argv[0]
%s -f <csv-file> [-p <KRAKENPAIR>] [--help] [--quiet] [--short]
To report only over one pair:
%s -f <csv-file> --pair XLTCXXBT
To save output in a file use shell redirect:
%s -f <csv-file> > reportfile.txt
To print output, pipe it through lp:
%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.exit(1)
@ -115,19 +124,18 @@ if __name__ == '__main__':
opts, args = parse_param(sys.argv[1:])
#print opts, args
quiet = False
pair_only = False
for opt, arg in opts:
if opt in ("-h", "--help"):
show_usage()
if opt in ("-f", "--file"):
filename = arg
if opt in ("-p", "--price"):
btc_price = float(arg)
if opt in ("-p", "--pair"):
pair_only = arg
if opt in ("-q", "--quiet", "-s", "--short"):
quiet = True
#filename = sys.argv[1]
#btc_price = float(sys.argv[2])
data = {}
krakenprice = get_krakenticker(KRK_TICKER_URL)['result']
#print krakenprice, type(krakenprice)
@ -145,20 +153,23 @@ if __name__ == '__main__':
# loop over each pair
pairs = data.keys()
for pair in pairs:
if pair_only and pair_only != pair:
print "Match, abort"
continue
print
price = float(krakenprice[pair]['c'][0].rstrip("0"))
#print "Current Krakenprice [%s]: %0.6f" %(pair, price,)
hrule("-")
print " "*25 + pair + " "*25
print " "*20 + pair + " [%0.6f]"%price + " "*20
hrule("-")
result_data[pair] = calc_totals(data[pair])
price = float(krakenprice[pair]['c'][0].rstrip("0"))
print "Current Krakenprice [%s]: %0.6f" %(pair, price,)
profit_buy = ( result_data[pair][0] * price ) - (result_data[price_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
profit_sell = ( result_data[pair][3] * price ) - (result_data[price_pair][3] * result_data[pair][5])
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
hrule("*")
#print "Result:", result_data
#print result_data[price_pair]
Loading…
Cancel
Save