-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add default plugin to track legacy and other trades manually
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import moment from 'moment'; | ||
import Plugin, { TRANSACTION_TYPE } from './common/plugin'; | ||
|
||
export default class DefaultPlugin extends Plugin { | ||
public getNames(): string[] { | ||
return ['legacy', 'others']; | ||
} | ||
|
||
// Date, Type, Name, Coin, Amount, Price, Total | ||
async convertRow(line: string[]): Promise<string[] | null> { | ||
const type = this._getType(line[1]); | ||
if (type === TRANSACTION_TYPE.UNKNOWN) { | ||
return Promise.resolve(null); | ||
} | ||
const date = new Date(Date.parse(line[0])); | ||
const amount = parseFloat(line[4]); | ||
const price = await this._api.getPrice(line[3], date); | ||
|
||
if (!price) { | ||
return Promise.resolve(null); | ||
} | ||
|
||
const row = this.toRow( | ||
date, | ||
type, | ||
line[2], | ||
price.coin.name, | ||
price.coin.symbol, | ||
amount, | ||
price?.price | ||
); | ||
return Promise.resolve(row); | ||
} | ||
|
||
private _getType(input: string): TRANSACTION_TYPE { | ||
if (input.includes('Buy')) { | ||
return TRANSACTION_TYPE.BUY; | ||
} | ||
if (input.includes('Withdraw')) { | ||
return TRANSACTION_TYPE.WITHDRAW; | ||
} | ||
if (input.includes('Trading')) { | ||
return TRANSACTION_TYPE.TRADING; | ||
} | ||
return TRANSACTION_TYPE.UNKNOWN; | ||
} | ||
} |