-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbinance.ts
49 lines (44 loc) · 1.25 KB
/
binance.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
import Plugin, { TRANSACTION_TYPE } from './common/plugin';
export default class Binance extends Plugin {
public getNames(): string[] {
return ['binance'];
}
// Date, Type, Name, Coin, Amount, Price, Total
async convertRow(line: string[]): Promise<string[] | null> {
const type = this._getType(line[3]);
if (type === TRANSACTION_TYPE.UNKNOWN) {
return Promise.resolve(null);
}
const date = new Date(Date.parse(line[1]));
const amount = parseFloat(line[5]);
const price = await this._api.getPrice(line[4], date);
if (!price) {
return Promise.resolve(null);
}
const row = this.toRow(
date,
type,
'Binance',
price.coin.name,
price.coin.symbol,
amount,
price?.price
);
return Promise.resolve(row);
}
private _getType(input: string): TRANSACTION_TYPE {
if (input.includes('Transaction Related') || input.includes('trading')) {
return TRANSACTION_TYPE.TRADING;
}
if (input.includes('Deposit')) {
return TRANSACTION_TYPE.DEPOSIT;
}
if (input.includes('Withdraw')) {
return TRANSACTION_TYPE.WITHDRAW;
}
if (input.includes('Withdraw')) {
return TRANSACTION_TYPE.WITHDRAW;
}
return TRANSACTION_TYPE.UNKNOWN;
}
}