-
Notifications
You must be signed in to change notification settings - Fork 1
/
youhodler.ts
65 lines (60 loc) · 1.89 KB
/
youhodler.ts
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
import moment from 'moment';
import Plugin, { TRANSACTION_TYPE } from './common/plugin';
export default class Youhodler extends Plugin {
public getNames(): string[] {
return ['youhodler'];
}
// TransactionId,AccountId,User,Status,Type,Ticker,Version,Amount,Fee,TxHash,CreatedAt
async convertRow(line: string[]): Promise<string[] | null> {
const type = this._getType(line[4]);
if (type === TRANSACTION_TYPE.UNKNOWN) {
return Promise.resolve(null);
}
const dateString = line[10];
// const date = moment(dateString, 'M/D/YY H:m').toDate(); //5/22/21 19:43
const date = new Date(Date.parse(dateString));
const coin = line[5].toUpperCase();
const amount = parseFloat(line[7]);
const price = await this._api.getPrice(coin, date);
if (!price) {
return Promise.resolve(null);
}
const row = this.toRow(
date,
type,
'Youhodler',
price.coin.name,
price.coin.symbol,
amount,
price.price
);
return Promise.resolve(row);
}
private _getType(input: string): TRANSACTION_TYPE {
if (input.includes('Savings earned')) {
return TRANSACTION_TYPE.LENDING;
}
if (input.includes('SAVING_EARN')) {
return TRANSACTION_TYPE.LENDING;
}
if (input.includes('Withdrawal')) {
return TRANSACTION_TYPE.WITHDRAW;
}
if (input.includes('WITHDRAWAL')) {
return TRANSACTION_TYPE.WITHDRAW;
}
if (input.includes('Deposit')) {
return TRANSACTION_TYPE.DEPOSIT;
}
if (input.includes('DEPOSIT')) {
return TRANSACTION_TYPE.DEPOSIT;
}
// TODO: info not in export (yet), return unkown
if (input.includes('EXCHANGE')) {
console.log('Youhodler: Found trade but info to which currency not in report yet');
console.log('--> Please add manually to other trades');
return TRANSACTION_TYPE.UNKNOWN;
}
return TRANSACTION_TYPE.UNKNOWN;
}
}