Skip to content

Commit

Permalink
feat: support liquid trades import
Browse files Browse the repository at this point in the history
  • Loading branch information
Zahrun committed Dec 13, 2022
1 parent 97b3986 commit 09bcb6b
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/parsers/trades/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import binanceParser from './binance';
import bittrexParser from './bittrex';
import geminiParser from './gemini';
import krakenParser from './kraken';
import liquidParser from './liquid';
import poloniexParser from './poloniex';
import revolutParser from './revolut';

Expand All @@ -12,6 +13,7 @@ const parserMapping: {[key in EXCHANGES]: any} = {
[EXCHANGES.Bittrex]: bittrexParser,
[EXCHANGES.Gemini]: geminiParser,
[EXCHANGES.Kraken]: krakenParser,
[EXCHANGES.Liquid]: liquidParser,
[EXCHANGES.Poloniex]: poloniexParser,
[EXCHANGES.Revolut]: revolutParser,
}
Expand Down
88 changes: 88 additions & 0 deletions src/parsers/trades/liquid/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { getCSVData } from '../../';
import { EXCHANGES, IImport, IPartialTrade, ITrade } from '../../../types';
import { createDateAsUTC, createID } from '../../utils';

interface ILiquid {
exchange: string;
currency_type: string;
direction: string;
transaction_id: string;
transaction_type: string;
gross_amount: string;
currency: string;
execution_id: string;
generated_for_type: string;
generated_for_id: string;
transaction_hash: string;
from_address: string;
to_address: string;
state: string;
created_at_jst: string;
updated_at_jst: string;
created_at_utc: string;
updated_at: string;
notes: string;
used_id: string;
account_id: string;
}

export default async function processData(importDetails: IImport): Promise<ITrade[]> {
const data: ILiquid[] = await getCSVData(importDetails.data) as ILiquid[];
const internalFormat: ITrade[] = [];
if (data.length < 1) {
return internalFormat;
}
let splitTrade = data[0];
let lineContinuity = 0;
for (const trade of data) {
const tradeToAdd: IPartialTrade = {
date : createDateAsUTC(new Date(trade.updated_at)).getTime(),
exchange : EXCHANGES.Liquid,
exchangeID : trade.execution_id,
};
switch (trade.transaction_type) {
case 'rebate_trade_fee':
case 'trade_fee':
case 'quick_exchange':
case 'trade': {
switch (lineContinuity) {
case 0: {
splitTrade = trade;
lineContinuity = 1;
continue;
}
case 1: {
lineContinuity = 0;
if (trade.direction === "pay" && splitTrade.direction === "receive") {
tradeToAdd.boughtCurrency = splitTrade.currency;
tradeToAdd.soldCurrency = trade.currency;
tradeToAdd.amountSold = Math.abs(parseFloat(trade.gross_amount));
tradeToAdd.rate = Math.abs(parseFloat(trade.gross_amount) / parseFloat(splitTrade.gross_amount));
} else if (trade.direction === "receive" && splitTrade.direction === "pay") {
tradeToAdd.soldCurrency = splitTrade.currency;
tradeToAdd.boughtCurrency = trade.currency;
tradeToAdd.amountSold = Math.abs(parseFloat(splitTrade.gross_amount));
tradeToAdd.rate = Math.abs(parseFloat(splitTrade.gross_amount) / parseFloat(trade.gross_amount));
} else {
console.error(`Error parsing ${trade.exchange} trade splitTrade.direction=${splitTrade.direction} and trade.direction=${trade.direction}`);
break;
}
tradeToAdd.ID = createID(tradeToAdd);
internalFormat.push(tradeToAdd as ITrade);
continue;
}
default: {
console.error(`Error parsing ${trade.exchange} trade lineContinuity=${lineContinuity}`);
break;
}
}
break;
}
default: {
console.log(`Ignored ${trade.exchange} trade of type ${trade.transaction_type}`);
continue;
}
}
}
return internalFormat;
}
4 changes: 4 additions & 0 deletions src/types/locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export type Location = EXCHANGES | string;
export enum EXCHANGES {
Bittrex = 'BITTREX',
Gemini= 'GEMINI',
Kraken = 'KRAKEN',
Liquid = 'LIQUID',
Poloniex = 'POLONIEX',
Kraken = 'KRAKEN',
Binance = 'BINANCE',
Expand All @@ -16,6 +18,8 @@ export enum IncomeImportTypes {
export enum ExchangesTradeHeaders {
BITTREX = '07230399aaa8d1f15e88e38bd43a01c5ef1af6c1f9131668d346e196ff090d80',
GEMINI = '996edee25db7f3d1dd16c83c164c6cff8c6d0f5d6b3aafe6d1700f2a830f6c9e',
KRAKEN = '85bf27e799cc0a30fe5b201cd6a4724e4a52feb433f41a1e8b046924e3bf8dc5',
LIQUID = '12c125c9080e41e087ff0955826bba94568d637214b166a296447e53ae469abe',
POLONIEX = 'd7484d726e014edaa059c0137ac91183a7eaa9ee5d52713aa48bb4104b01afb0',
KRAKEN = '85bf27e799cc0a30fe5b201cd6a4724e4a52feb433f41a1e8b046924e3bf8dc5',
BINANCE = '4d0d5df894fe488872e513f6148dfa14ff29272e759b7fb3c86d264687a7cf99',
Expand Down

0 comments on commit 09bcb6b

Please sign in to comment.