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
4 changes: 3 additions & 1 deletion src/parsers/trades/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import geminiParser from './gemini';
import krakenParser from './kraken';
import poloniexParser from './poloniex';
import revolutParser from './revolut';
import pionexParser from './pionex';

const parserMapping: {[key in EXCHANGES]: any} = {
[EXCHANGES.Binance]: binanceParser,
Expand All @@ -14,6 +15,7 @@ const parserMapping: {[key in EXCHANGES]: any} = {
[EXCHANGES.Kraken]: krakenParser,
[EXCHANGES.Poloniex]: poloniexParser,
[EXCHANGES.Revolut]: revolutParser,
[EXCHANGES.Pionex]: pionexParser,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly is the difference between pionex and the dust parser?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dust parser is for the dust collector feature in Pionex, it is in a separate csv file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a different format, hence the different header

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, I am not familiar with Pionex, I am just trying to understand if its actually an exchange, or if its simple transactions or incomes, or something else entirely?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is an exchange specialized in trading bots, with mostly trades and transactions.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but what is this dust collector? Are they actually trades too?

I think it might be better(assuming these are trades), to change the format so each exchange supports an array of hashes to match against and then in your parser you can check to see if its dust or not and then process based on that. So users dont need to choose

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Dust Collector is a feature on Pionex exchange that helps you collect all the small left behind assets into a whole. For example, when you convert btc to usdt there are a little fraction that is left behind. The dust collector helps you collect them."

I have seen that on other exchanges too. I think legally it must be considered a trade, at least in my country.
It allows converting very small amount of crypto into USDT usually when the amount is too small to do a normal trade.

Another use is when there are many different coins left, even if the amount is not that small, it will convert all into one coin.

I like your approach, so I will try to implement that testing against an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that will mess with my other PRs. Let’s try to merge the other ones first.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay going to leave this one then as is and work on reviewing the other ones and getting them merged first

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I included a way to support multiple hashes which is very little breaking, so that it will be easy to merge

}

export default async function processTradesImport(importDetails: IImport): Promise<ITrade[]> {
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
89 changes: 89 additions & 0 deletions src/parsers/trades/pionex/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { getCSVData } from '../../';
import { EXCHANGES, IImport, IPartialTrade, ITrade } from '../../../types';
import { createDateAsUTC, createID } from '../../utils';

enum PionexOrderSide {
SELL = 'SELL',
BUY = 'BUY',
}

interface IPionex {
'date(UTC+0)': string;
amount: string;
price: string;
order_price: string;
side: string;
symbol: string;
state: string;
fee: string;
strategy_type: string;
}

export default async function pionexParser(importDetails: IImport): Promise<ITrade[]> {
if (importDetails.data.split(',')[2] === '\"coin\"') {
console.log('Detected Pionex dust collector')
return pionexDustParser(importDetails);
}
const data: IPionex[] = await getCSVData(importDetails.data) as IPionex[];
const internalFormat: ITrade[] = [];
for (const trade of data) {
const tradeToAdd: IPartialTrade = {
date: createDateAsUTC(new Date(trade['date(UTC+0)'])).getTime(),
exchange: EXCHANGES.Pionex,
};
if (trade.state === 'CANCELED') {
console.log('Skipping canceled trade');
continue;
}
if (trade.side.toUpperCase() === PionexOrderSide.BUY) {
const [boughtCurrency, soldCurrency] = trade.symbol.split('_');
tradeToAdd.boughtCurrency = boughtCurrency;
tradeToAdd.soldCurrency = soldCurrency;
tradeToAdd.amountSold = parseFloat(trade.amount);
tradeToAdd.rate = parseFloat(trade.price);
} else if (trade.side.toUpperCase() === PionexOrderSide.SELL) {
const [soldCurrency, boughtCurrency] = trade.symbol.split('_')
tradeToAdd.soldCurrency = soldCurrency;
tradeToAdd.boughtCurrency = boughtCurrency;
tradeToAdd.amountSold = parseFloat(trade.amount) / parseFloat(trade.price);
tradeToAdd.rate = 1 / parseFloat(trade.price);
} else {
console.error('Trade side unknown');
continue;
}
tradeToAdd.tradeFee = parseFloat(trade.fee);
tradeToAdd.tradeFeeCurrency = tradeToAdd.boughtCurrency;
tradeToAdd.ID = createID(tradeToAdd);
tradeToAdd.exchangeID = tradeToAdd.ID;
internalFormat.push(tradeToAdd as ITrade);
}
return internalFormat;
}


interface IPionexDust {
'date(UTC+0)': string;
amount: string;
coin: string;
price: string;
swap_value: string;
}

export async function pionexDustParser(importDetails: IImport): Promise<ITrade[]> {
const data: IPionexDust[] = await getCSVData(importDetails.data) as IPionexDust[];
const internalFormat: ITrade[] = [];
for (const trade of data) {
const tradeToAdd: IPartialTrade = {
date : createDateAsUTC(new Date(trade['date(UTC+0)'])).getTime(),
exchange : EXCHANGES.Pionex,
boughtCurrency : 'USDT',
soldCurrency : trade.coin,
amountSold : parseFloat(trade.amount),
rate : 1 / parseFloat(trade.price),
};
tradeToAdd.ID = createID(tradeToAdd);
tradeToAdd.exchangeID = tradeToAdd.ID;
internalFormat.push(tradeToAdd as ITrade);
}
return internalFormat;
}
11 changes: 7 additions & 4 deletions src/types/locations.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export type Location = EXCHANGES | string;

export enum EXCHANGES {
Binance = 'BINANCE',
Bittrex = 'BITTREX',
Gemini= 'GEMINI',
Poloniex = 'POLONIEX',
Kraken = 'KRAKEN',
Binance = 'BINANCE',
Pionex = 'PIONEX',
Poloniex = 'POLONIEX',
Revolut = 'REVOLUT',
}

Expand All @@ -14,10 +15,12 @@ export enum IncomeImportTypes {
}

export enum ExchangesTradeHeaders {
BINANCE = '4d0d5df894fe488872e513f6148dfa14ff29272e759b7fb3c86d264687a7cf99',
BITTREX = '07230399aaa8d1f15e88e38bd43a01c5ef1af6c1f9131668d346e196ff090d80',
GEMINI = '996edee25db7f3d1dd16c83c164c6cff8c6d0f5d6b3aafe6d1700f2a830f6c9e',
POLONIEX = 'd7484d726e014edaa059c0137ac91183a7eaa9ee5d52713aa48bb4104b01afb0',
KRAKEN = '85bf27e799cc0a30fe5b201cd6a4724e4a52feb433f41a1e8b046924e3bf8dc5',
BINANCE = '4d0d5df894fe488872e513f6148dfa14ff29272e759b7fb3c86d264687a7cf99',
PIONEX = 'a09d295de934a0015f3c3abf40c87de620adcc4e41af8c684581a8f3c04952f1;\
be6b0243d74515e9ed1c01488e37b1ea169caf7e00dbddc70c99ef3596e77509',
POLONIEX = 'd7484d726e014edaa059c0137ac91183a7eaa9ee5d52713aa48bb4104b01afb0',
REVOLUT = 'ef10a780b82fdd31bb5b5f4f21eb7332c46b324513ab15418448f360f268e37c',
}
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