-
Notifications
You must be signed in to change notification settings - Fork 4
feat: import pionex trades #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Zahrun
wants to merge
4
commits into
starsoccer:master
Choose a base branch
from
Zahrun:pionex
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
starsoccer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| tradeToAdd.exchangeID = tradeToAdd.ID; | ||
starsoccer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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