-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
46 lines (43 loc) · 1.14 KB
/
index.js
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
#!/usr/bin/env node
const fs = require('fs')
const argv = require('optimist').argv
const csv = require('csv')
fs.createReadStream(argv._[0])
.pipe(csv.parse({columns: true, relax_column_count: true, delimiter: '\t'}))
.pipe(csv.transform((record) => {
let [Fee] = record.Fee.split(' ')
let [GFee] = record['Gas Fee'].split(' ')
GFee = Number(GFee)
Fee = Number(Fee)
if (Number.isNaN(Fee)) {
Fee = 0
}
if (!Number.isNaN(GFee)) {
Fee += GFee
}
let Buy, CurB, Sell, CurS
if (record.Type === 'Buy') {
[Buy, CurB] = record.Amount.split(' ');
[Sell, CurS] = record.Total.split(' ')
} else if (record.Type === 'Sell') {
[Sell, CurS] = record.Amount.split(' ');
[Buy, CurB] = record.Total.split(' ')
}
return {
Type: 'Trade',
Buy,
CurB,
Sell,
CurS,
Fee,
CurF: CurB,
Exchange: 'Idex',
Group: '',
Comment: '',
'Trade ID': record['Transaction ID'],
Date: record.Date
}
}))
.pipe(csv.stringify({header: true}))
.pipe(fs.createWriteStream(
`${argv._[0].split('.')[0]}FormatedForCoinTracking.csv`))