Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support coinlist trades import #280

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions components/TradesTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class TradesTable extends React.Component<ITradeTableProps, {popup: strin
'Bought Currency',
'Amount Bought',
'Transaction Fee',
'Trade Fee',
'',
]}
rows={this.props.trades.map((trade) => [
Expand All @@ -66,6 +67,7 @@ export class TradesTable extends React.Component<ITradeTableProps, {popup: strin
<span>{trade.boughtCurrency}</span>,
<span>{(trade.amountSold / trade.rate).toFixed(8)}</span>,
<span>{`${trade.transactionFee} ${trade.transactionFeeCurrency}`}</span>,
<span>{`${trade.tradeFee} ${trade.tradeFeeCurrency}`}</span>,
<i className='fa fa-pencil-square' onClick={this.changePopupStatus(trade.ID)}/>,
])}
/>
Expand Down
93 changes: 93 additions & 0 deletions src/parsers/trades/coinlist/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { getCSVData } from '../../';
import { EXCHANGES, IImport, IPartialTrade, ITrade } from '../../../types';
import { createID } from '../../utils';

interface ICoinList {
Date: string;
Description: string;
Asset: string;
Amount: string;
Balance: string;
}

interface ICoinListPro {
portfolio: string;
type: string;
time: string;
amount: string;
balance: string;
'amount/balance unit': string;
transaction_id: string
}

export default async function processData(importDetails: IImport): Promise<ITrade[]> {
if (importDetails.data.split(',')[0] === 'portfolio') {
console.log('Detected CoinListPro')
return processProData(importDetails);
}
const data: ICoinList[] = await getCSVData(importDetails.data) as ICoinList[];
const internalFormat: ITrade[] = [];
for (let i = 0; i < data.length; i++) {
const trade = data[i];
const tradeToAdd: IPartialTrade = {
date : new Date(trade.Date).getTime(),
exchange : EXCHANGES.CoinList,
};
let descriptionSplit = trade.Description.split(' ');
let type = descriptionSplit[0];
switch (type) {
case 'Sold':
case 'Bought': {
i++;
tradeToAdd.boughtCurrency = trade.Asset;
tradeToAdd.soldCurrency = data[i].Asset;
tradeToAdd.amountSold = Math.abs(parseFloat(data[i].Amount));
tradeToAdd.rate = Math.abs(parseFloat(data[i].Amount) / parseFloat(trade.Amount));
tradeToAdd.ID = createID(tradeToAdd);
tradeToAdd.exchangeID = tradeToAdd.ID;
internalFormat.push(tradeToAdd as ITrade);
continue;
}
// TODO: Withdrawal, Distribution, Deposit, Hold
default: {
console.log(`Ignored ${tradeToAdd.exchange} trade of type ${type}`);
break;
}
}
}
return internalFormat;
}

export async function processProData(importDetails: IImport): Promise<ITrade[]> {
const data: ICoinListPro[] = await getCSVData(importDetails.data) as ICoinListPro[];
const internalFormat: ITrade[] = [];
for (let i = 0; i < data.length; i++) {
const trade = data[i];
const tradeToAdd: IPartialTrade = {
date : new Date(trade.time).getTime(),
exchange : EXCHANGES.CoinList,
};
switch (trade.type) {
case 'match': {
i++;
tradeToAdd.boughtCurrency = trade.balance;
tradeToAdd.tradeFee = Math.abs(parseFloat(data[i].amount));
tradeToAdd.tradeFeeCurrency = data[i].balance;
i++;
tradeToAdd.soldCurrency = data[i].balance;
tradeToAdd.amountSold = Math.abs(parseFloat(data[i].amount));
tradeToAdd.rate = Math.abs(parseFloat(data[i].amount) / parseFloat(trade.amount));
tradeToAdd.ID = createID(tradeToAdd);
tradeToAdd.exchangeID = tradeToAdd.ID;
internalFormat.push(tradeToAdd as ITrade);
continue;
}
// TODO: deposit, withdrawal
default: {
console.log(`Ignored ${tradeToAdd.exchange} trade of type ${trade.type}`);
break;
}
}
}
return internalFormat;
}
4 changes: 3 additions & 1 deletion src/parsers/trades/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EXCHANGES, ExchangesTradeHeaders, IImport, ITrade } from '@types';
import * as crypto from 'crypto';
import binanceParser from './binance';
import bittrexParser from './bittrex';
import coinListParser from './coinlist';
import geminiParser from './gemini';
import krakenParser from './kraken';
import poloniexParser from './poloniex';
Expand All @@ -10,6 +11,7 @@ import revolutParser from './revolut';
const parserMapping: {[key in EXCHANGES]: any} = {
[EXCHANGES.Binance]: binanceParser,
[EXCHANGES.Bittrex]: bittrexParser,
[EXCHANGES.CoinList]: coinListParser,
[EXCHANGES.Gemini]: geminiParser,
[EXCHANGES.Kraken]: krakenParser,
[EXCHANGES.Poloniex]: poloniexParser,
Expand All @@ -24,7 +26,7 @@ export default async function processTradesImport(importDetails: IImport): Promi
const headers = importDetails.data.substr(0, importDetails.data.indexOf('\n'));
const headersHash = crypto.createHash('sha256').update(headers).digest('hex');
for (const key in ExchangesTradeHeaders) {
if (ExchangesTradeHeaders[key] === headersHash) {
if (ExchangesTradeHeaders[key].split(';').includes(headersHash)) {
return processTradesImport({
...importDetails,
location: key,
Expand Down
3 changes: 3 additions & 0 deletions src/types/locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export type Location = EXCHANGES | string;

export enum EXCHANGES {
Bittrex = 'BITTREX',
CoinList = 'COINLIST',
Gemini= 'GEMINI',
Poloniex = 'POLONIEX',
Kraken = 'KRAKEN',
Expand All @@ -15,6 +16,8 @@ export enum IncomeImportTypes {

export enum ExchangesTradeHeaders {
BITTREX = '07230399aaa8d1f15e88e38bd43a01c5ef1af6c1f9131668d346e196ff090d80',
COINLIST = 'a700f71b8629872a0d8d5320612aedcb53f58cc55937eb146124a14360d991f1;\
9eccf556ea42d14253a223980bf0023f6cc0d21320db187f6b9b6bbf59ea8678',
GEMINI = '996edee25db7f3d1dd16c83c164c6cff8c6d0f5d6b3aafe6d1700f2a830f6c9e',
POLONIEX = 'd7484d726e014edaa059c0137ac91183a7eaa9ee5d52713aa48bb4104b01afb0',
KRAKEN = '85bf27e799cc0a30fe5b201cd6a4724e4a52feb433f41a1e8b046924e3bf8dc5',
Expand Down
2 changes: 2 additions & 0 deletions src/types/trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface ITrade {
ID: string;
transactionFee: number;
transactionFeeCurrency: string;
tradeFee?: number;
tradeFeeCurrency?: string;
}

export interface ITradeWithFiatRate extends ITrade {
Expand Down