-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.js
73 lines (62 loc) · 1.89 KB
/
app.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
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
'use strict';
require('./init');
const config = require('./config');
const { calculateGains, truncateGains, printSummary } = require('./src/calculategains');
const cleanData = require('./src/cleandata');
const importCoinbase = require('./src/sources/coinbase');
const importGDAX = require('./src/sources/gdax');
const importPoloniex = require('./src/sources/poloniex');
const importFile = require('./src/sources/file');
config.getDisposalMethod = function getDisposalMethod(year) {
let method = config.disposalMethod[year];
// convert string into object
if (typeof method === 'string' || typeof method === 'undefined') {
method = { method };
}
// default to FIFO
if (!method.method) {
method.method = 'FIFO';
}
if (method.method === 'Estimate') {
for (const prop of ['shortTermTaxRate', 'longTermTaxRate']) {
if (!method[prop] || method[prop] <= 0 || method[prop] >= 1) {
throw new Error(`invalid ${prop} for ${year}: ${method[prop]}`);
}
}
}
return method;
};
async function importAccounts() {
for (const account of config.accounts) {
// parse importStartDate
if (account.importStartDate) {
account.importStartDate = Date.parse(`${account.importStartDate} UTC`);
}
switch (account.source) {
case 'coinbase':
await importCoinbase(account);
break;
case 'gdax':
await importGDAX(account);
break;
case 'poloniex':
await importPoloniex(account);
break;
case 'file':
await importFile(account);
break;
default:
throw new Error(`unknown account source: ${account.source}`);
}
}
}
async function main() {
await truncateGains();
await importAccounts();
await cleanData();
await calculateGains(config);
await printSummary(config);
console.log('\nComplete!');
}
main().catch(err => console.error(err.stack))
.then(() => process.exit());