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

interface IGateIO {
No: string;
'Account Type': string;
Time: string;
'Action type': string;
Currency: string;
'Order id': string;
'Change amount': string;
Amount: string;
'Additional Info': string;
}

interface IGateIOGroup {
[key: string]: IGateIO[];
}

function groupByOrderID(group: IGateIOGroup, line: IGateIO) {
group[line['Order id']] = group[line['Order id']] ?? [];
group[line['Order id']].push(line);
return group;
}

export default async function processData(importDetails: IImport): Promise<ITrade[]> {
const data: IGateIO[] = await getCSVData(importDetails.data) as IGateIO[];
const internalFormat: ITrade[] = [];
const grouped = data.reduce(groupByOrderID, {});
for (const order in grouped) {
const trades = grouped[order];
const tradeToAdd: IPartialTrade = {
date : createDateAsUTC(new Date(trades[0].Time)).getTime(),
exchangeID : order,
exchange : EXCHANGES.GateIO,
};
switch (trades[0]['Action type']) {
case 'Trading Fees': {
for (let i = 0; i < trades.length; i += 3) {
let newTrade = tradeToAdd;
if (trades[i+1]['Action type'] !== 'Order Filled' || trades[i+2]['Action type'] !== 'Order Placed') {
console.error(`Error parsing ${newTrade.exchange} trade
trades[i+1]['Action type'] = ${trades[i+1]['Action type']}
trades[i+2]['Action type'] = ${trades[i+2]['Action type']}`);
}
newTrade.boughtCurrency = trades[i+1].Currency;
newTrade.soldCurrency = trades[i+2].Currency;
newTrade.amountSold = Math.abs(parseFloat(trades[i+2]['Change amount']));
newTrade.rate = Math.abs(parseFloat(trades[i+2]['Change amount']) / parseFloat(trades[1]['Change amount']));
newTrade.tradeFeeCurrency = trades[i].Currency;
newTrade.tradeFee = Math.abs(parseFloat(trades[i]['Change amount']));
newTrade.ID = createID(newTrade);
internalFormat.push(newTrade as ITrade);
}
break;
}
case 'Points Purchase': {
if (trades[1]['Action type'] !== 'Points Purchase') {
console.error(`Error parsing ${tradeToAdd.exchange} points purchase
trades[1]['Action type'] = ${trades[1]['Action type']}`);
}
tradeToAdd.boughtCurrency = trades[0].Currency;
tradeToAdd.soldCurrency = trades[1].Currency;
tradeToAdd.amountSold = Math.abs(parseFloat(trades[1]['Change amount']));
tradeToAdd.rate = Math.abs(parseFloat(trades[1]['Change amount']) /
parseFloat(trades[0]['Change amount']));
tradeToAdd.ID = createID(tradeToAdd);
internalFormat.push(tradeToAdd as ITrade);
break;
}
// TODO: Deposits, Airdrop, Withdrawals, Points With Expiration, Quant- Transferred In, Quant- Transferred Out
default: {
console.log(`Ignored Gate.io trade of type ${trades[0]['Action type']}`);
continue;
}
}
}
return internalFormat;
}
2 changes: 2 additions & 0 deletions 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 gateIOParser from './gate.io';
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.GateIO]: gateIOParser,
[EXCHANGES.Gemini]: geminiParser,
[EXCHANGES.Kraken]: krakenParser,
[EXCHANGES.Poloniex]: poloniexParser,
Expand Down
2 changes: 2 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',
GateIO = 'GATE_IO',
Gemini= 'GEMINI',
Poloniex = 'POLONIEX',
Kraken = 'KRAKEN',
Expand All @@ -15,6 +16,7 @@ export enum IncomeImportTypes {

export enum ExchangesTradeHeaders {
BITTREX = '07230399aaa8d1f15e88e38bd43a01c5ef1af6c1f9131668d346e196ff090d80',
GATE_IO = '99ff90ddaa0826df50d15296f504ca71e4b04dff45ae7798e7ba5f688fec9209',
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