-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbitpanda.ts
60 lines (55 loc) · 1.64 KB
/
bitpanda.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
import moment from 'moment';
import Plugin, { TRANSACTION_TYPE } from './common/plugin';
export default class Bitpanda extends Plugin {
public getNames(): string[] {
return ['bitpanda'];
}
// "Transaction ID",Timestamp,"Transaction Type",In/Out,"Amount Fiat",Fiat,"Amount Asset",Asset,"Asset market price","Asset market price currency","Asset class","Product ID",Fee,"Fee asset",Spread,"Spread Currency"
async convertRow(line: string[]): Promise<string[] | null> {
const type = this._getType(line[2]);
if (type === TRANSACTION_TYPE.UNKNOWN) {
return Promise.resolve(null);
}
const date = new Date(Date.parse(line[1]));
const coin = line[7].toUpperCase();
let amount
if (line[6] !== '-') {
amount = parseFloat(line[6]);
} else {
amount = parseFloat(line[4]);
}
let name;
if (coin === 'BEST') {
name = 'Bitpanda Ecosystem Token';
}
const price = await this._api.getPrice(coin, date, name);
if (!price) {
return Promise.resolve(null);
}
const row = this.toRow(
date,
type,
'Bitpanda',
price.coin.name,
price.coin.symbol,
amount,
price.price
);
return Promise.resolve(row);
}
private _getType(input: string): TRANSACTION_TYPE {
if (input.includes('transfer') || input.includes('deposit')) {
return TRANSACTION_TYPE.DEPOSIT;
}
if (input.includes('buy')) {
return TRANSACTION_TYPE.BUY;
}
if (input.includes('withdrawal')) {
return TRANSACTION_TYPE.WITHDRAW;
}
if (input.includes('sell')) {
return TRANSACTION_TYPE.SELL;
}
return TRANSACTION_TYPE.UNKNOWN;
}
}