From f44d1324f6a8adbc52e68bbe7e6e666512d1a212 Mon Sep 17 00:00:00 2001 From: Zahrun <10415894+Zahrun@users.noreply.github.com> Date: Sun, 11 Dec 2022 22:19:56 +0100 Subject: [PATCH] feat: support coinlist trades import --- src/parsers/trades/coinlist/index.ts | 58 ++++++++++++++++++++++++++++ src/parsers/trades/index.ts | 2 + src/types/locations.ts | 2 + 3 files changed, 62 insertions(+) create mode 100644 src/parsers/trades/coinlist/index.ts diff --git a/src/parsers/trades/coinlist/index.ts b/src/parsers/trades/coinlist/index.ts new file mode 100644 index 0000000..695a080 --- /dev/null +++ b/src/parsers/trades/coinlist/index.ts @@ -0,0 +1,58 @@ +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; +} + +export default async function processData(importDetails: IImport): Promise { + const data: ICoinList[] = await getCSVData(importDetails.data) as ICoinList[]; + const internalFormat: ITrade[] = []; + if (data.length < 1) { + return internalFormat; + } + let splitTrade = data[0]; + let lineContinuity = 0; + for (const trade of data) { + console.log(trade); + const tradeToAdd: IPartialTrade = { + date : new Date(trade.Date).getTime(), + exchange : EXCHANGES.CoinList, + }; + let descriptionSplit = trade.Description.split(' '); + let type = descriptionSplit[0]; + if (type === 'Sold' || type === 'Bought') { + switch (lineContinuity) { + case 0: { + splitTrade = trade; + lineContinuity = 1; + continue; + } + case 1: { + lineContinuity = 0; + tradeToAdd.boughtCurrency = splitTrade.Asset; + tradeToAdd.soldCurrency = trade.Asset; + tradeToAdd.amountSold = Math.abs(parseFloat(trade.Amount)); + tradeToAdd.rate = Math.abs(parseFloat(trade.Amount) / parseFloat(splitTrade.Amount)); + tradeToAdd.ID = createID(tradeToAdd); + internalFormat.push(tradeToAdd as ITrade); + continue; + } + default: { + console.error(`Error parsing CoinList trade lineContinuity=${lineContinuity}`); + break; + } + } + break; + } else { + console.log(`Ignored CoinList trade of type ${type}`); + continue; + } + } + return internalFormat; +} diff --git a/src/parsers/trades/index.ts b/src/parsers/trades/index.ts index 30b720d..ef59523 100644 --- a/src/parsers/trades/index.ts +++ b/src/parsers/trades/index.ts @@ -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'; @@ -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, diff --git a/src/types/locations.ts b/src/types/locations.ts index c0053d4..2c05bd5 100644 --- a/src/types/locations.ts +++ b/src/types/locations.ts @@ -2,6 +2,7 @@ export type Location = EXCHANGES | string; export enum EXCHANGES { Bittrex = 'BITTREX', + CoinList = 'COINLIST', Gemini= 'GEMINI', Poloniex = 'POLONIEX', Kraken = 'KRAKEN', @@ -15,6 +16,7 @@ export enum IncomeImportTypes { export enum ExchangesTradeHeaders { BITTREX = '07230399aaa8d1f15e88e38bd43a01c5ef1af6c1f9131668d346e196ff090d80', + COINLIST = 'a700f71b8629872a0d8d5320612aedcb53f58cc55937eb146124a14360d991f1', GEMINI = '996edee25db7f3d1dd16c83c164c6cff8c6d0f5d6b3aafe6d1700f2a830f6c9e', POLONIEX = 'd7484d726e014edaa059c0137ac91183a7eaa9ee5d52713aa48bb4104b01afb0', KRAKEN = '85bf27e799cc0a30fe5b201cd6a4724e4a52feb433f41a1e8b046924e3bf8dc5',