improved, cleaned up, bugfix

main
psycodad 2 years ago
parent 8fd4382ccb
commit d37091d762

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