Skip to content
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
82 changes: 82 additions & 0 deletions src/parsers/trades/aax/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { getCSVData } from '../../';
import { EXCHANGES, IImport, IPartialTrade, ITrade } from '../../../types';
import { createDateAsUTC, createID } from '../../utils';

interface IAAX {
Coin: string;
Quantity: string;
Type: string;
Details: string;
Time: string;
}

interface IAAXGroup {
[key: string]: IAAX[];
}

function groupByType(group: IAAXGroup, line: IAAX) {
group[line.Type] = group[line.Type] ?? [];
group[line.Type].push(line);
return group;
}

export default async function processData(importDetails: IImport): Promise<ITrade[]> {
const data: IAAX[] = (await getCSVData(importDetails.data) as IAAX[]);
const internalFormat: ITrade[] = [];
for (let i = 0; i < data.length; i++) {
const tradeToAdd: IPartialTrade = {
date : createDateAsUTC(new Date(data[i].Time)).getTime(),
exchange : EXCHANGES.AAX,
};
switch (data[i].Type) {
case 'Trading': {
const trades = [data[i], data[++i], data[++i]];
const groupedTrades = trades.reduce(groupByType, {});
internalFormat.push(addTrade(tradeToAdd, groupedTrades['Trading'][0], groupedTrades['Trading'][1], groupedTrades['Trading Fee'][0]));
break;
}
case 'Convert': {
internalFormat.push(addTrade(tradeToAdd, data[i], data[++i]));
break;
}
// TODO: Withdrawal, Deposit, System Deposit, Fixed Interest, Flexible Interest
default: {
console.log(`Ignored ${tradeToAdd.exchange} trade of type ${data[i].Type}`);
}
}
}
return internalFormat;
}

function addTrade(
tradeToAdd: IPartialTrade,
firstHalf: IAAX,
secondHalf: IAAX,
feeTrade?: IAAX,
): ITrade {
let firstHalfDirection = parseFloat(firstHalf.Quantity) > 0;
let secondHalfDirection = parseFloat(secondHalf.Quantity) > 0;
if (firstHalfDirection && !secondHalfDirection) {
tradeToAdd.boughtCurrency = firstHalf.Coin;
tradeToAdd.soldCurrency = secondHalf.Coin;
tradeToAdd.amountSold = Math.abs(parseFloat(secondHalf.Quantity));
tradeToAdd.rate = Math.abs(parseFloat(secondHalf.Quantity) / parseFloat(firstHalf.Quantity));
} else if (!firstHalfDirection && secondHalfDirection) {
tradeToAdd.soldCurrency = firstHalf.Coin;
tradeToAdd.boughtCurrency = secondHalf.Coin;
tradeToAdd.amountSold = Math.abs(parseFloat(firstHalf.Quantity));
tradeToAdd.rate = Math.abs(parseFloat(firstHalf.Quantity) / parseFloat(secondHalf.Quantity));
} else {
console.info(firstHalf);
console.info(secondHalf);
throw new Error(`Error parsing ${tradeToAdd.exchange} firstHalf.direction=${firstHalfDirection}
and secondHalf.direction=${secondHalfDirection}`);
}
if (feeTrade !== undefined) {
tradeToAdd.tradeFee = Math.abs(parseFloat(feeTrade.Quantity));
tradeToAdd.tradeFeeCurrency = feeTrade.Coin;
}
tradeToAdd.ID = createID(tradeToAdd);
tradeToAdd.exchangeID = tradeToAdd.ID;
return tradeToAdd as ITrade;
}
2 changes: 2 additions & 0 deletions src/parsers/trades/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EXCHANGES, ExchangesTradeHeaders, IImport, ITrade } from '@types';
import * as crypto from 'crypto';
import aaxParser from './aax'
import binanceParser from './binance';
import bittrexParser from './bittrex';
import geminiParser from './gemini';
Expand All @@ -8,6 +9,7 @@ import poloniexParser from './poloniex';
import revolutParser from './revolut';

const parserMapping: {[key in EXCHANGES]: any} = {
[EXCHANGES.AAX]: aaxParser,
[EXCHANGES.Binance]: binanceParser,
[EXCHANGES.Bittrex]: bittrexParser,
[EXCHANGES.Gemini]: geminiParser,
Expand Down
2 changes: 2 additions & 0 deletions src/types/locations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type Location = EXCHANGES | string;

export enum EXCHANGES {
AAX = 'AAX',
Bittrex = 'BITTREX',
Gemini= 'GEMINI',
Poloniex = 'POLONIEX',
Expand All @@ -14,6 +15,7 @@ export enum IncomeImportTypes {
}

export enum ExchangesTradeHeaders {
AAX = '5aaccf9d0910e5c227f7590bfd39c8baa883bde920c5da39f06c29447b78d80f',
BITTREX = '07230399aaa8d1f15e88e38bd43a01c5ef1af6c1f9131668d346e196ff090d80',
GEMINI = '996edee25db7f3d1dd16c83c164c6cff8c6d0f5d6b3aafe6d1700f2a830f6c9e',
POLONIEX = 'd7484d726e014edaa059c0137ac91183a7eaa9ee5d52713aa48bb4104b01afb0',
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