From df5542b7e68afd49be81b2f19bf863685e6f6978 Mon Sep 17 00:00:00 2001 From: psycodad Date: Fri, 2 Dec 2022 16:22:17 +0100 Subject: [PATCH] basic functions working, no output yet --- kraken-report.py | 103 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100755 kraken-report.py diff --git a/kraken-report.py b/kraken-report.py new file mode 100755 index 0000000..0bff3f6 --- /dev/null +++ b/kraken-report.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# --------------------------------------------------------------------- +# Copyright (c) 2022 BOXTEC AG +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. The name of the author may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, +# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +# THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# -------------------------------------------------------------------------- + +####################### +# IMPORTS +####################### +import csv, sys + + +####################### +# FUNCTIONS +####################### +def calc_totals(trades): + #print trades + sum_s1 = 0 + sum_s2 = 0 + sum_b1 = 0 + sum_b2 = 0 + for t in trades: + print t['time'], t['pair'], t['type'], t['price'], t['vol'], t['cost'] + if t['type'] == 'sell': + sum_s1 += float(t['vol']) + sum_s2 += float(t['cost']) + elif t['type'] == 'buy': + sum_b1 += float(t['vol']) + sum_b2 += float(t['cost']) + if sum_s1 > 0 and sum_s2 >0: + avg_s = sum_s2 / sum_s1 + else: + avg_s = 0 + if sum_b1 > 0 and sum_b2 >0: + avg_b = sum_b2 / sum_b1 + else: + avg_b = 0 + + print "SUMS:", sum_s1, sum_s2, avg_s, sum_b1, sum_b2, avg_b + return [sum_s1, sum_s2, avg_s, sum_b1, sum_b2, avg_b,] + +####################### +# MAIN +####################### +if __name__ == '__main__': + + print sys.argv + if len(sys.argv) < 3: + print """ +Usage: + %s +""" %sys.argv[0] + sys.exit(1) + + filename = sys.argv[1] + btc_price = float(sys.argv[2]) + data = {} + + + # loop over all data and sort into pairs + fh = open(filename, 'r') + csv_data = csv.DictReader(fh) + for line in csv_data: + if not data.has_key(line['pair']): + data[line['pair']] = [] + data[line['pair']].append(line) + + # dict of data to hold all totals for all pairs + result_data = {} + # loop over each pair + pairs = data.keys() + for pair in pairs: + print "*"*20 + pair + "*"*20 + result_data[pair] = calc_totals(data[pair]) + print "Result:", result_data + + + \ No newline at end of file