This repository has been archived by the owner on Dec 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidex2ct.py
95 lines (83 loc) · 2.7 KB
/
idex2ct.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python
# coding=utf-8
import csv
import sys
# bei True: Gebuhren (Fee + GasFee) von dem Buy-Wert anziehen
# bei False: nix tun
flagFeesAbziehen = True
if len(sys.argv) == 1:
print("Fehler! Bitte Dateiname uebergeben!")
print("")
print(
"Usage: idex2ct.py <inputFile> [Y/N = Fees Abziehen vom Buy-Betrag; Default Y] ")
print("")
print("OutputFile ist <inputFile>._UploadCT.csv")
print("")
exit()
inputFilename = sys.argv[1]
outputFilename = str(inputFilename.split('.')[0]) + "_UploadCT.csv"
if (len(sys.argv) > 2) and (sys.argv[2] == "N"):
flagFeesAbziehen = False
with open(outputFilename, 'w') as csvfile:
fieldnames = [
'Type',
'Buy',
'CurB',
'Sell',
'CurS',
'Fee',
'CurF',
'Exchange',
'Group',
'Comment',
'Trade ID',
'Date']
writer = csv.DictWriter(
csvfile,
fieldnames=fieldnames,
lineterminator='\r\n')
writer.writeheader()
with open(inputFilename, 'r') as csvfile:
inputReader = csv.DictReader(csvfile, delimiter='\t')
for row in inputReader:
# Defaults
Type = 'Trade'
Buy = ''
CurB = ''
Sell = ''
CurS = ''
if (row['Type'] == 'Buy'):
[Buy, CurB] = row['Amount'].split(' ')
[Sell, CurS] = row['Total'].split(' ')
elif (row['Type'] == 'Sell'):
[Sell, CurS] = row['Amount'].split(' ')
[Buy, CurB] = row['Total'].split(' ')
# Fee
Fee = 0.0
GFee = 0.0
try:
CurF = row['Fee'].split(' ')[1]
Fee = float(row['Fee'].split(' ')[0])
except ValueError as e:
Fee = 0.0
# print(e.message)
try:
GFee = float(row['Gas Fee'].split(' ')[0])
except ValueError as e:
GFee = 0.0
# print(e.message)
# Fee = Fee + Gas Fee
Fee += float(GFee)
# Fees abziehen?
if flagFeesAbziehen:
Buy = float(Buy) - Fee
if CurF != CurB:
print("FEHLER!?!?! CurF != CurB?")
Exchange = 'Idex'
Group = ''
Comment = ''
TradeID = row['Transaction ID']
Date = row['Date']
writer.writerow({
'Type': Type, 'Buy': Buy, 'CurB': CurB, 'Sell': Sell, 'CurS': CurS, 'Fee': Fee, 'CurF': CurF, 'Exchange': Exchange, 'Group': Group, 'Comment': Comment, 'Trade ID': TradeID, 'Date': Date})
print("Done: " + inputFilename + " --> " + outputFilename + " erstellt.")